我想用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