1

I am having a VF where the user will browse the file and in the apex, I am encoding that file and uploading it to sharepoint and storing the response in salesforce. I am not storing the file/request in salesforce.

I am facing issues when the user uploads more that 5 mb of file as it exceed the heap size limit. user can select file upto 10 mb.

Can we upload the image directly from VF using some java script to sharepoint. I will need to perform authentication(BASIC) as well and get the response and show it to user.

If yes, will i be able to encode the file which user selected directly in VF or I need to do the encoding in apex?

I researched a lot and could see that this can be achieved using JavaScript but could not find any sample code for this. Is it possible to get some sample code to achieve this?

3
  • 1
    To get past the 6MB limit, you'll need to use the AJAX Proxy. – sfdcfox May 31 '18 at 20:15
  • @sfdcfox - thanks. Will there be any issue for cross site calls? – Samir Jun 1 '18 at 11:05
  • The caveat is you can only access sites you configure in Remote Site Settings. Assuming you configure this correctly, you can use the proxy for payloads far above the 6MB limit. I think I remember testing this once with a 100MB+ file and it worked. – sfdcfox Jun 1 '18 at 11:24
-2

Would something like this be helpful at all?

Specifically, the JSForce plugin will allow you to make a request using the {!$Api.Session_Id} field:

 var conn = new jsforce.Connection({ accessToken: '{!$Api.Session_Id}' });

Then you can post to the chatter API as seen here:

var path = '/services/data/v40.0';
return conn.requestPost( path + '/composite/', {
    'allOrNone' : true,
    'compositeRequest' : [
        {
            'method' : 'POST',
            'url' : path + '/sobjects/ContentVersion',
            'referenceId' : 'newFile',
            'body' : {
                'Title' : fileName,
                'PathOnClient' : fileName,
                'VersionData' : base64,
                'FirstPublishLocationId' : recordId
            }
        }
    ]
});

The use of the existing session id should overcome any CORS issues you're having.

3
  • Thanks for the response but this is more of a upload to salesforce. I need other details as how to authenticate and avoid CORS request from browser – Samir May 31 '18 at 10:57
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – David Reed May 31 '18 at 11:40
  • @DavidReed Good shout, thanks. I've updated with code snippets. – Jeff Bennett May 31 '18 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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