I have the below code where in we are accepting the blob data from the REST Apex class. We are inserting the document (blob) that we are receiving as a feed item. I was able to send file sizes upto 54 MB after which it started erroring out.
The governor limit states that the heap size for synchronous transactions is 6MB then how is it that this REST class is able to accept file sizes 9 times the heap size limit? and when we print the limits in the debug even that is not showing a high number at all. Where is this file stored when the class receives it ? How is the heap size getting calculated?
@RestResource(urlMapping='/uploadFile/*')
global class REST_StoreAttachment {
@httpPost
global static String postMethod(){
Blob requestBody=RestContext.request.requestBody;
system.debug('Heap size before'+ limits.getHeapSize() + ' ==== '+ Limits.getLimitHeapSize());
ContentVersion content = new ContentVersion();
content.Title = 'test';
content.PathOnClient = 'fileName.txt';
content.VersionData = requestBody;
content.Origin = 'H';
insert content;
FeedItem post = new FeedItem();
post.ParentId = '00000000000000'; //hard coded to a Id
post.Body = 'New attachment added';
post.RelatedRecordId = content.Id;
post.Type = 'ContentPost';
insert post;
system.debug('Heap size after'+ limits.getHeapSize() + ' ==== '+ Limits.getLimitHeapSize());
return 'success';
}
}
System Debug
Heap size before2189 ==== 6000000
Heap size after2514 ==== 6000000