0

I am consistently getting corrupted content on retrieving it using REST API, using SOAP flow is working fine on the other hand.

One example of what's happening :

  1. I upload a PDF file under Files for a Case from Salesforce.
  2. I use a query on ContentVersion -> VersionData to get the file URL as described at https://developer.salesforce.com/forums/?id=9060G0000005UKWQA2.
  3. I make another REST call to retrieve the file content based on the URL.
  4. I receive and download the file content and create a PDF file using the same
  5. On opening the file, it is blank.

Notes :

  1. The same is not observed for text files using a small charset of english letters.
  2. Images are created but I am unable to open those

I am using a Java client to retrieve the file content, have used POSTMAN calls as well and received similar output from the REST API.

Also PFB sample of file uploaded to Salesforce -> input.pdf and file created using the file content received from the REST API -> output.pdf. Opening the same in any text editor shows that some part of the file is corrupted probably due to some charset issue.

input.pdf :

%PDF-1.4
%âãÏÓ
2 0 obj
<</Length 67/Filter/FlateDecode>>stream
x<9c>+är
á26S°00S^HIá2P0^@Qún<86>
<86>@<81>4°<80><81>BQ:<97><86>GjNN¾Bx~QN<8a>fH^VP"^]¦Ú5<84>+<90>^K^@ZL^PÁ
endstream
endobj
4 0 obj
<</Type/Page/MediaBox[0 0 595 842]/Resources<</Font<</F1 1 0 R>>>>/Contents 2 0 R/Parent 3 0 R>>
endobj
1 0 obj
<</Type/Font/Subtype/Type1/BaseFont/Courier/Encoding/WinAnsiEncoding>>
endobj
3 0 obj
<</Type/Pages/Count 1/Kids[4 0 R]>>
endobj
5 0 obj
<</Type/Catalog/Pages 3 0 R>>
endobj
6 0 obj
<</Producer(iText® 5.5.10 ©2000-2015 iText Group NV \(AGPL-version\))/CreationDate(D:20211201171521+05'30')/ModDate(D:20211201171521+05'30')>>
endobj
xref
0 7
0000000000 65535 f
0000000260 00000 n
0000000015 00000 n
0000000346 00000 n
0000000148 00000 n
0000000397 00000 n
0000000442 00000 n
trailer
<</Size 7/Root 5 0 R/Info 6 0 R/ID [<7936c63bea484b2997b0082042255f58><7936c63bea484b2997b0082042255f58>]>>
%iText-5.5.10
startxref
600
%%EOF

output.pdf :

%PDF-1.4
%����
2 0 obj
<</Length 67/Filter/FlateDecode>>stream
x�+�r
�26S�00S^HI�2P0^@Q�n�
�@�4���BQ:��GjNN�Bx~QN�fH^VP"^]��5�+�^K^@ZL^P�
endstream
endobj
4 0 obj
<</Type/Page/MediaBox[0 0 595 842]/Resources<</Font<</F1 1 0 R>>>>/Contents 2 0 R/Parent 3 0 R>>
endobj
1 0 obj
<</Type/Font/Subtype/Type1/BaseFont/Courier/Encoding/WinAnsiEncoding>>
endobj
3 0 obj
<</Type/Pages/Count 1/Kids[4 0 R]>>
endobj
5 0 obj
<</Type/Catalog/Pages 3 0 R>>
endobj
6 0 obj
<</Producer(iText� 5.5.10 �2000-2015 iText Group NV \(AGPL-version\))/CreationDate(D:20211201171521+05'30')/ModDate(D:20211201171521+05'30')>>
endobj
xref
0 7
0000000000 65535 f
0000000260 00000 n
0000000015 00000 n
0000000346 00000 n
0000000148 00000 n
0000000397 00000 n
0000000442 00000 n
trailer
<</Size 7/Root 5 0 R/Info 6 0 R/ID [<7936c63bea484b2997b0082042255f58><7936c63bea484b2997b0082042255f58>]>>
%iText-5.5.10
startxref
600
%%EOF
1
  • This looks like an decoding/encoding problem. What header attributes does your REST call use? Anything with charset? Commented Dec 2, 2021 at 15:09

1 Answer 1

0

I was able to resolve the issue by avoiding to convert the HttpResponse into a String first. On using the byte array from the HttpResponse to to create the file(using ByteArrayInputStream), I was able to get the file content correctly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .