cancel
Showing results for 
Search instead for 
Did you mean: 

Document content gets corrupted on upload

nilofar_sayyad
Champ in-the-making
Champ in-the-making
Hi,

We are using Alfresco 3.3 with websphere AS 7.0.0.0. When the document is uploaded,the content of the document gets corrupted for word,excel and editable pdf files.Number of bytes written and read while downloading are same.When we download these files the files are corrupted and do not open.
Below is the code for uploading document:
<java>
String docChildRef = Constants.createQNameString(
                  NMSPCE_KYC_CNTNT_MDL, TYPE_KYC_DOCUMENT + timeStamp);
            ParentReference docParent = new ParentReference(getStoreRef(),
                  null, clientFolder, Constants.ASSOC_CONTAINS,
                  docChildRef);
String name = documentId + CommonConstants.TILDE + docTitle
                  + CommonConstants.TILDE + versionId
                  + CommonConstants.TILDE + fileName; /
NamedValue nameValue = Utils.createNamedValue(
                  Constants.PROP_NAME, name);
            NamedValue[] namePropsArr = new NamedValue[] { nameValue };

            // Construct CML statement to create document content node
            String contentType = Constants.createQNameString(
                  NMSPCE_KYC_CNTNT_MDL, TYPE_KYC_DOCUMENT);
            CMLCreate createDoc = new CMLCreate("ref2", // id
                  docParent, null, null, null, contentType, namePropsArr);
            

            // Add custom properties to the folder using CMLAddAspect
            String docAspect = Constants.createQNameString(
                  NMSPCE_KYC_CNTNT_MDL, ASPECT_KYC_DOCUMENT);
            NamedValue documentIdValue=null;
      if(null!=documentId){
             documentIdValue = Utils.createNamedValue(Constants
                  .createQNameString(NMSPCE_KYC_CNTNT_MDL,
                        PROP_DOCUMENT_ID), documentId.toString());
             }
            NamedValue uploadedByValue = Utils.createNamedValue(Constants
                  .createQNameString(NMSPCE_KYC_CNTNT_MDL,
                        PROP_UPLOADED_BY), uploadedBy);
            NamedValue versionIdValue = Utils.createNamedValue(Constants
                  .createQNameString(NMSPCE_KYC_CNTNT_MDL,
                        PROP_VERSION_ID), versionId.toString());
            NamedValue clientUuidValue = Utils.createNamedValue(
                  Constants.createQNameString(NMSPCE_KYC_CNTNT_MDL,
                        PROP_CLIENT_ID), clientUuid.toString());
            NamedValue[] contentPropsArr = new NamedValue[] { nameValue,
                  documentIdValue, uploadedByValue, versionIdValue,
                  clientUuidValue };
            CMLAddAspect documentAspect = new CMLAddAspect(docAspect,
                  contentPropsArr, null, "ref2"); // the "ref2" used here
                                          // must be equal to the
                                          // id parameter in
                                          // CMLCreate

            // Add title and description properties to the folder using
            // CMLAddAspect
            NamedValue documentTitle = Utils.createNamedValue(
                  Constants.PROP_TITLE, docTitle);
            NamedValue documentDesciption = Utils.createNamedValue(
                  Constants.PROP_DESCRIPTION, docDescription);
            NamedValue[] titledPropsArr = new NamedValue[] { documentTitle,
                  documentDesciption };
            CMLAddAspect titleAspect = new CMLAddAspect(
                  Constants.ASPECT_TITLED, titledPropsArr, null, "ref2");

            // Construct CML Block
            CML cml = new CML();
            cml.setCreate(new CMLCreate[] { createDoc });
            cml.setAddAspect(new CMLAddAspect[] { documentAspect,
                  titleAspect });
            try {
               // Execute CML Block
               UpdateResult[] updatedResultArr = getRepositoryService()
                     .update(cml);
               Reference docRef = updatedResultArr[0].getDestination();

               // Write the contents into repository using contentService
               byte[] fileCntntByteArr = documentVO.getFileContent();
               System.out.println("bytes to be written:"+ fileCntntByteArr.length);
               if (fileCntntByteArr.length != 0) {
                  ContentFormat contentFormat = new ContentFormat(
                        mimeType, CONTNT_ENCODNG_FRMT);
                  Content content = getContentService().write(docRef,
                        Constants.PROP_CONTENT, fileCntntByteArr,
                        contentFormat);
<java>
Please help me in this case.
13 REPLIES 13

Sorry, I could not see any attachments in your reply.

Actually i also did not get to see any attachment in your reply. Smiley Happy that is why i uploaded screenshot in my reply.When i navigate to sites i get message 'This space is managed by Alfresco Share. Please use the Alfresco Share application to work with content within this space and any sub-spaces.' and under Browse Spaces-'No items to display. Click the 'Create Space' action to create a space.'and under Content Items-'No items to display. To add an existing document click 'Add Content' action. To create an HTML or Plain Text file click 'Create Content' action.'

Are you able to see the sites from Share application?

You can also use node browser to get the content type and encoding information.

Navigate to,
Node Browser–> Company Home–> Sites–>  Your site name –> document libaray –> filename.txt

and look at the Content property of the document.

It will look like  something below,
{http://www.alfresco.org/model/content/1.0}content   
contentUrl=store://2013/2/22/11/0/32261a1e-86ba-4416-b9e8-18610607c946.bin|mimetype=text/plain|size=5841|encoding=UTF-8|locale=en_US_|id=240

Hope this helps you !

Hi,

I checked the content type and encoding.Encoding is UTF-8 and content type is MS word which is correct.Also i have verified if not all bytes are written while uploading but all bytes are also written to the server.When we download and try to open the file the contents are corrupted.