我想用Apache Chemistry OpenCMIS将文件上传到我的Alfresco仓库。 文件已创建且属性正确,但没有内容,文件为0字节。我仔细检查过,源文件没有错。 这里是我的Java代码:用OpenCMIS上传文件没有内容
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);
}
没有任何异常捕捉。
谢谢,这对我有用! – dumazy