You need to sign in to do that
Don't have an account?
Suman Kuch
Uploading large files failing (5mb+)
Hi,
We are replacing native functionality of Attachments to upload files to "Box"external storage using Rest API, I was able to upload small files upto 5MB but when trying to upload big files I get the error in Apex code (not even going to box)
Error is triggering at "bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);" this line.
Please advice how can we ignore the size of the file? We need to upload at least 10 MB.
Thanks,
Sumant K
We are replacing native functionality of Attachments to upload files to "Box"external storage using Rest API, I was able to upload small files upto 5MB but when trying to upload big files I get the error in Apex code (not even going to box)
System.StringException: String length exceeds maximum: 6000000This is occurig when trying to decoding ( base64Decode ) from String blob before Rest API call, please check the code.
String bodyEncoded = EncodingUtil.base64Encode(fileBody); Blob bodyBlob = null; String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length()); // GW: replacement section to get rid of padding without corrupting data if(last4Bytes.endsWith('==')) { last4Bytes = last4Bytes.substring(0,2) + '0K'; bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes; String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer)); bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded); //Here its failing }else if(last4Bytes.endsWith('=')){ last4Bytes = last4Bytes.substring(0,3) + 'N'; bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes; footer = '\n' + footer; String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer)); bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded); }else{ footer = '\r\n' + footer; String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer)); bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded); }
Error is triggering at "bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);" this line.
Please advice how can we ignore the size of the file? We need to upload at least 10 MB.
Thanks,
Sumant K
Unfortunately, your SOL when it comes to that sort of limit, you're only route is going to be moving the operation off Salesforce.
One option would be to create a Heroku app with a single endpoint that takes the attachment Id. The endpoint can then retrieve the attachment and then upload it to the 3rd party server.
For more information please check with below links which might help you.
- http://salesforce.stackexchange.com/questions/29141/string-length-exceeds-maximum-6000000
- https://developer.salesforce.com/forums/?id=906F0000000kEAgIAM
Mark this as solved if the information helps.Regards,
Nagendra.
Did you ever fixed this? I am facing similar issue. Could you please help.
Unfortunately I couldn't upload morethan 5 MB with Apex so I had to write javascript code in Visualsource and used XMHttpRequest to upload file, this allowing me to upload upto 1GB file. Salesforce will not care if you use javascript.
Can you please share the code which you used to upload the file to google drive will really appreciate if you can guide me in this reference.