function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DevidDevid 

How to upload more than 20MB File using HTTP Reuqest from Salesoforce to dropbox?

This below code is working perfect with 10 mb but when I try to upload more than 10mb file then it throws an error.
 
private string TOKEN = 'access_token_of_dropbox_app';//
string folderPathWithFileName;
for(ContentVersion contentVersionRec : [SELECT PathOnClient, VersionData FROM contentversion
										   WHERE contentdocumentId IN : contentDocumentIdSet){
	folderPathWithFileName = '/Root/'+PathOnClient;//PathOnClient contains file name with extension like imagefile.png
	system.debug('###folderPathWithFileName=>'+folderPathWithFileName);
	Http http = new Http();
	HttpRequest httpReq = new HttpRequest();
	httpReq.setEndpoint('https://content.dropboxapi.com/2/files/upload');
	httpReq.setMethod('POST');
	httpReq.setHeader('Authorization','Bearer ' + TOKEN);
	httpReq.setHeader('Content-Type','application/octet-stream');
	httpReq.setHeader('Dropbox-API-Arg','{"path":"'+folderPath+'","mode":{".tag":"add"}}');
	httpReq.setBodyAsBlob(contentVersionRec.VersionData);
	HttpResponse httpResponse = http.send(httpReq);
	System.debug('res###' + httpResponse);
	System.debug('res.getBody()###'+httpResponse.getBody());
	if (httpResponse.getStatusCode() == 200) {
		System.debug('##Congratulations File Uploaded successfully :) =>'+httpResponse.getBody());
	}else{
		//Handle code here when file not uploaded. 
	}
}

The error is : System.CalloutException: Exceeded max size limit of 12000000 with request size 12001280

I know(limit while sending http request) reason of this error but there should be a way to send more than 10mb file. Actually I need to upload up to 100 mb file from http request(Salesoforce) to dropbox.

If anyone have any idea please let me know.
AbhishekAbhishek (Salesforce Developers) 
Hi,

This error message is due to a maximum size of call out response which is 6MB. This error is typical because of the following issue 

              a) (Maximum size of callout request or response) 
              b) maximum allowed heap size (6MB sync / 12MB async).
 
You may also try to set up the debug logs and check for the Apex heap size error to confirm. 

I would like to mention that the limit for both max sizes of call out (request and response ) and heap size is 6MB. 

Best practices for running within the Apex heap size 
https://help.salesforce.com/apex/HTViewSolution?urlname=Apex-Heap-Size-Best-Practices&language=en_US  (https://help.salesforce.com/apex/HTViewSolution?urlname=Apex-Heap-Size-Best-Practices&language=en_US )

https://help.salesforce.com/apex/HTViewSolution?urlname=How-to-avoid-the-Apex-heap-limit-error&language=en_US

(https://help.salesforce.com/apex/HTViewSolution?urlname=How-to-avoid-the-Apex-heap-limit-error&language=en_US )


Even if you contact Salesforce support the limit can not get increased permanently.


For further reference, you can check the below blog too,

https://www.forcetalks.com/blog/what-to-do-when-salesforce-apex-heap-size-increases/

I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.


Thanks.