cancel
Showing results for 
Search instead for 
Did you mean: 

Error downloading word, excel files using webservices

sharon
Champ in-the-making
Champ in-the-making
Hi,

I have been using Alfresco Labs 3 Full Setup for Document Management integrated with my application.
Any file of Microsoft word or excel format gets uploaded into Alfresco repository.
When i try to open it using Alfresco Web client, It opens properly.  Smiley Happy
However, when i try to open the uploaded file through my application, it gives me "unknown file format" error.
I have debugged my application and realised that the content downloaded from alfresco is corrupted.  :cry:
The byte array obtained contains corrupted data due to which i get the above error.
The code for downloading is given below:

Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");
Content[] contentResultArr = WebServiceFactory.getContentService().read(
         new Predicate(new Reference[] { new Reference(storeRef, nodeId, null) }, storeRef, null),
         Constants.PROP_CONTENT);

Content content = contentResultArr[0];
InputStream outFileContent = ContentUtils.getContentAsInputStream(content);
byte [] contentByteArr = ContentUtils.convertToByteArray(outFileContent);
outFileContent.close();

Kindly help me out with this issue.
2 REPLIES 2

norgan
Champ in-the-making
Champ in-the-making
Hi,
what do you get instead ? I used to work with a Firefox Plugin "PDF Download", but could not download PDFs with this plugin, which were coming from Alfresco. The authentification information got lost on the way and I always got a document with the correct name & extension, but with the "HTML Login.jsp" sourcecode as real content.

My only solution was to not use "PDF Download" so far.

Norgan

sharon
Champ in-the-making
Champ in-the-making
The problem arises when i try to download my content using the convertToByteArray() metohd of ContentUtils:


Content content = contentResultArr[0];
InputStream inputSteam= ContentUtils.getContentAsInputStream(content);
byte [] contentByteArr = ContentUtils.convertToByteArray(inputSteam);
outFileContent.close();

The InputStream that i receive is perfect (with say length=18k bytes) , but when i try to convert the input stream to byte array, the total byte size reduces to 16K. This happens with all the file formats(word/excel/pdf) with size greater than 16k bytes since the inputSteam.isAvailable() function used internally in convertToByteArray() return only 16k bytes at a time.

I got this rectified by using the getContentAsString() line :

Content content = contentResultArr[0];
String contentString= ContentUtils.getContentAsString(content);
byte [] contentByteArr = contentString.getBytes();
outFileContent.close();

This solves the byte size prob.  Smiley Happy
However, now when trying to view the file, it gives memory error.  :cry:

Temporarily, as a solution, I write the content onto the local system using
ContentUtils.copyContentToFile(content, file);
and read the content from the file using I/O stream.

If any one can help me read out the content directly from alfresco repository, through any other way besides ContentUtils let me know.

Sharon.