Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a VF page that is used to load files to AWS. In the past the files were smaller and the 5M VF limit was fine. Now most of the files are larger than 5M and I can no longer upload them using this VF page.

What is the workaround or alternative?

share|improve this question
What error are you getting? The maximum size for a file upload is documented as 10MB here, salesforce.com/us/developer/docs/pages/Content/… –  Andrew Fawcett Jan 29 '13 at 16:52
Your right, I meant to write 10M (5M is the old limit). 10M is also too small for me. Any suggestion beside ajax toolkit? –  Dedo Jan 30 '13 at 6:40
add comment

1 Answer

Use the ajax toolkit to perform the upload from javascript. This way you avoid apex heap size limit. I've done it and successfully uploaded files up to ~35 mb in size.

1) Reference the ajax toolkit in your visualforce page.

<apex:includeScript value="../../soap/ajax/26.0/connection.js" />

2) Write javascript to upload to server (in this case its as an attachment, but contents or documents should also work).

function uploadAttachment(filecontent, filename, filetype, parentId) {
    var attachment         = new sforce.SObject('Attachment');
    attachment.Name        = filename;
    attachment.IsPrivate   = false;
    attachment.ContentType = filetype;
    attachment.Body        = filecontent;
    attachment.Description = filename;
    attachment.ParentId    = parentId;

3) Write some js to get at file content. This is the only difficult step. You could use HTML5 file API but its support is limited. Ill do a drag-n-drop example as its more supported.

    var dropzone = document.getElementById('dropzone');
    dropzone.addEventListener("drop", drop, false);

    function drop(evt) {
        var files = evt.originalEvent.dataTransfer.files;            
        if (files.length > 0) {
            try {
            } catch(error) {
                alert('An error occured in sfdc-dragndrop.js: ' + error);

    function uploadFiles(files) {
        for(var index = 0, file; file = files[index]; index++) {
            var reader = new FileReader();

            reader.onloadend = 
                (function(file) { 
                     return function(evt) {
                         var fileContent = getFileContent(evt.target.result)
                         var parentId    = <id of attachment parent>;
                         uploadAttachment(fileContent, file.name, file.type, parentId);


    function getFileContent(fileData) {
        var fileContent = String(fileData);
        return fileContent.substr(fileContent.indexOf(',') + 1);

Hopefully all that code works and gets you what you need (i dug it out of an old project and changed it a little on the fly to be stackexchange-friendly), if not it should be a step in the right direction.

share|improve this answer
Thanks. I'm not sure how to do it. Can you maybe share a code sample? –  Dedo Jan 30 '13 at 6:42
can you share some sample of how to achieve this using the AJAX toolkit? –  Dedo Mar 4 '13 at 12:04
Updated answer based on comments. –  Phil Rymek Mar 4 '13 at 17:36
Thanks Phil, will give it a try –  Dedo Mar 4 '13 at 18:23
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.