java - Upload File with OpenCMIS has no content -
i'm trying upload file alfresco repository using apache chemistry opencmis. file created , properties correct there no content, file 0 bytes. i've double checked , there nothing wrong source file. here's java code:
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); } there no exception catched.
i think there problem content stream passing.
try replace code
string doctext = "this sample document"; byte[] content = doctext.getbytes(); inputstream stream = new bytearrayinputstream(content); contentstream contentstream = getsession().getobjectfactory().createcontentstream(filename, long.valueof(content.length), "text/plain", stream); you can gradually change simple text content new file in next step.
Comments
Post a Comment