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

lista
Star Contributor
Star Contributor
Can you check content-type and encoding properties of the document through Alfresco Explorer? Hopefully, that will be a clue as to what exactly is happening.

nilofar_sayyad
Champ in-the-making
Champ in-the-making
thanks for your reply Lista.Could you please let me know where can i check the content-type and encoding properties of the document through alfresco explorer.

Hi,
Navigate to Alfresco Explorer application (http://localhost:8080/alfresco).
Go to  Company Home–>Sites–>Your SiteName–>DocumentLibrary–>FileName–>View Details.
In this page, check the Properties section which contains the Name, Content-type and Encoding properties.

        Name:    test file.txt
   Content Type:   Plain Text
   Encoding:   UTF-8
   Title:   test file.txt
   Description:   

Hope this helps you.

when i navigate to Company Home->Sites the message i get is 'This space is managed by Alfresco Share. Please use the Alfresco Share application to work with content within this space and any sub-spaces.' Do i need to integrate Alfresco Share.Please let me know as i am very new to alfresco.

Hi,
Just you're going to verify the content type and encoding details of a particular , so it is not a problem for you.

But i am not able to get my site listed down here.Please see the attached screenshot.

But i am not able to get my site listed down here.

Hi,
Have you logged into alfresco explorer application?
Click Company Home–>Sites–> It will list out all the existing sites.
Are you able to see other sites?
Please find the attached.

<strong> Note : </strong> Download the attachment and change the extension to jpg.

nilofar_sayyad
Champ in-the-making
Champ in-the-making
I am not able to see any sites listed.Please find the attachment.After download change the extension to jpg