gpt4 book ai didi

java - 使用 OpenCMIS 上传文件没有内容

转载 作者:行者123 更新时间:2023-11-30 06:25:07 24 4
gpt4 key购买 nike

我正在尝试使用 Apache Chemistry OpenCMIS 将文件上传到我的 Alfresco 存储库。文件已创建且属性正确但没有内容,文件为 0 字节。我已经仔细检查过,源文件没有任何问题。这是我的 Java 代码:

File content = new File(somepath);
try{
String mimeType = new MimetypesFileTypeMap().getContentType(content);
logger.debug("mimetype: " + mimeType);
logger.debug("file: " + content.getAbsolutePath());
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
properties.put(PropertyIds.NAME, content.getName());


FileInputStream fis = new FileInputStream(content);
DataInputStream dis = new DataInputStream(fis);
byte[] bytes = new byte[(int) content.length()];
dis.readFully(bytes);

ContentStream cs = new ContentStreamImpl(content.getName(), BigInteger.valueOf(bytes.length), mimeType, dis);
Folder folder = (Folder) session.getObjectByPath("/myfolder");
Document doc = folder.createDocument(properties, cs, VersioningState.MAJOR);
return doc.getId();
}catch(CmisBaseException e){
logger.error("error uploading file: "+ e.getMessage(), e);
}

没有捕获到异常。

最佳答案

我认为您传递的内容流有问题。

尝试用这个替换你的代码

String docText = "This is a sample document";
byte[] content = docText.getBytes();
InputStream stream = new ByteArrayInputStream(content);
ContentStream contentStream = getSession().getObjectFactory().createContentStream(filename, Long.valueOf(content.length), "text/plain", stream);

您可以在下一步中使用新文件中的内容逐渐更改此简单文本。

关于java - 使用 OpenCMIS 上传文件没有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16087397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com