Salesforce to Amazon S3 file upload - Heap Limit Exceeded

Author - Webner

How to resolve “Heap Limit Exceeded” error while uploading large files to Amazon S3 from within Salesforce.

Amazon Toolkit from Force.com has inbuilt classes and methods that facilitate connecting to Amazon S3 from Salesforce and uploading files to Amazon S3 from within Salesforce. For that we generally write a controller that receives the uploaded file from VisualForce page, connects to S3 bucket with its URL, defines parameter values for attributes like AWSAccessKeyId, x-amz-meta-uuid etc and uploads the file. But when file of size greater than 2MB is uploaded to Amazon S3, this approach generates “Heap Limit Exceeded” error.

The signed object would go in your HTML in a form like this:

<HTML>

<head>

...

<meta http-equiv="Content-Type" content="text/HTML; charset=UTF-8" />

...

</head>

<body>

...

<form action="http://bucketname.s3.amazonaws.com/" method="post" enctype="multipart/form-data">

Key to upload: <input type="input" name="key" value="val" /><br />

<input type="hidden" name="acl" value="public-read" />

<input type="hidden" name="success_action_redirect" value="http://bucketname.s3.amazonaws.com/successful_upload.HTML" />

Content-Type: <input type="input" name="Content-Type" value="image/jpeg" /><br />

<input type="hidden" name="x-amz-meta-uuid" value="14365123651274" />

Tags for File: <input type="input" name="x-amz-meta-tag" value="" /><br />

<input type="hidden" name="AWSAccessKeyId" value="valueofkey" />

<input type="hidden" name="object" value="object" />

<input type="hidden" name="Signature" value="SIGNATURE" />

File: <input type="file" name="file" /> <br />

<!-- The elements after this will be ignored -->

<input type="submit" name="submit" value="Upload to Amazon S3" />

</form>

...

</HTML

The FORM action sends file directly to Amazon S3 and not via server.

Webner Solutions is a Software Development company focused on developing CRM apps (Salesforce, Zoho), LMS Apps (Moodle/Totara), Websites and Mobile apps. If you need Salesforce customization, App development or any other software development assistance please contact us at salesforce@webners.com

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *