[SalesForce] Retrieving VersionData with standard REST API

I am trying to retrieve VersionData with a standard REST API call from a VisualForce Page a then upload it to a S3 bucket but end up with corrupted files. I believe this is an encoding problem on the client side as plain text or CSVs work like a charm. I can upload VersionData from Apex but there are heap and request size limitations so I need to send the data from the client.

enter image description here
This is the call and returned string, I tried changing mimeType and encoding on both sides (SF call and S3 upload) with no luck.

Any ideas how to properly process images or pdf files? Thanks a lot

THE PROBLEM IS NOW SOLVED

Files should not be treated as strings. I solved the problem by leaving jQuery's ajax as I did not succeed to request a response type. By switching to plain JS and making a GET call (XMLHttpRequest) with response type set to blob I received an Object, instead of a string. Base64 string can be then retreived using JS FileReader.

Best Answer

The problem was jQuery ajax method.

XMLHttpRequest with responseType set to "blob" solved the problem.

Related Topic