将文件添加到FileNet对象存储,但当我检索它时,它是空的,0字节文件

本文关键字:文件 字节 检索 FileNet 添加 对象 存储 | 更新日期: 2023-09-27 18:16:58

我能够使用他们的API (Filenet .API.dll) v5.2.1成功发送文件到Filenet,但当我试图检索它时,它是一个0字节的文件,没有内容。

这实际上是使用在他们的c#演示程序中找到的方法来发送和接收这里找到的文件(http://www-01.ibm.com/support/docview.wss?uid=swg24028791)

与我的场景的不同之处在于,我将有源数据已经在流形式,所以我不需要像演示那样将本地文件转换为流。

下面的方法被运行:或多或少按这个顺序,有些是重复的。

主创建文档方法执行

                IDocument doc = CreateDocument(stream, fnDoc.mimeType, fnDoc.docName, fnRepo.os, "Common", paRequest);
                IFolder folder = FetchFolder(fnRepo.os, "/");
                doc.Save(RefreshMode.REFRESH);
                IReferentialContainmentRelationship rcr = FileContainable(fnRepo.os, doc, folder);
                rcr.Save(RefreshMode.REFRESH);
                checkInDoc(doc);

上面列出的方法如下

    public static IDocument CreateDocument(Stream stream, String mimeType, String docName, IObjectStore os, String className)
    {
        IDocument doc = null;
        if (className.Equals(""))
            doc = Factory.Document.CreateInstance(os, null);
        else
            doc = Factory.Document.CreateInstance(os, className);
        doc.Properties["DocumentTitle"] = docName;
        doc.MimeType = mimeType;
        IContentElementList cel = CreateContentElementList(stream, docName);
        if (cel != null)
            doc.ContentElements = cel;
        return doc;
    }

下一个是CreateContentElementList

    public static IContentElementList CreateContentElementList(Stream stream, string docName)
    {
        IContentElementList cel = null;
        if (CreateContentTransfer(stream, docName) != null)
        {
            cel = Factory.ContentElement.CreateList();
            IContentTransfer ct = CreateContentTransfer(stream, docName);
            cel.Add(ct);
        }
        return cel;
    }

最后CreateContentTransfer

    public static IContentTransfer CreateContentTransfer(Stream stream, string docName)
    {
        IContentTransfer ct = null;
        ct = Factory.ContentTransfer.CreateInstance();
        ct.SetCaptureSource(stream);
        ct.RetrievalName = docName; 
        return ct;
    }

此时ct的长度和大小不存在,但这些可以手动设置,所以我不确定这是否重要。而且变量流仍然有内容。

从CreateDocument

返回文档

然后获取文件夹

    public static IFolder FetchFolder(IObjectStore os, String fPath)
    {
        IFolder f = Factory.Folder.FetchInstance(os, fPath, null);
        return f
    }
然后

    public static IReferentialContainmentRelationship FileContainable(IObjectStore os, IContainable c, IFolder folder)
    {
        IReferentialContainmentRelationship rcr = null;
        if (c is IDocument)
            rcr = folder.File((IDocument)c, AutoUniqueName.AUTO_UNIQUE, ((IDocument)c).Name, DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
        else
            rcr = folder.File((ICustomObject)c, AutoUniqueName.AUTO_UNIQUE, ((ICustomObject)c).Name, DefineSecurityParentage.DO_NOT_DEFINE_SECURITY_PARENTAGE);
        return rcr;
    }
    public static void checkInDoc(IDocument doc)
    {
        doc.Checkin(AutoClassify.AUTO_CLASSIFY, CheckinType.MINOR_VERSION);
        doc.Save(RefreshMode.REFRESH);
        doc.Refresh();
    }

所以我错过了什么,一些最后的部分,实际上把内容放在服务器上或什么?

将文件添加到FileNet对象存储,但当我检索它时,它是空的,0字节文件

当调用ct.SetCaptureSource(stream);时,流应该是未读的(或者可能是流的位置重置),以便API可以捕获所需的文件。

如果流的位置在流的末尾,你将不会最终发送任何东西到IContentTransfer对象,导致ContentElement包含0字节。