2

I'm trying to upload an attachment from SF to a third party server using REST API,

First, my third party does not support base64 content-transfer so I cannot send from SF a base64 attachment.

Second - once the attachment is larger than 100KB, I get this exception (works well with files smaller than 100KB) :

System.UnexpectedException: Script-thrown exception

This is my code - I wrote a very simple code for testing, and I am testing with pdf / docx files:

private static HttpResponse sendAttachment(Attachment caseAtt, String endpoint){

    HttpRequest req = new HttpRequest();
    req.setMethod('POST');
    req.setHeader('Accept', 'application/xml');
    req.setHeader('Content-Type', 'multipart/form-data'); //tried with 'application/pdf' (for pdf file)
    req.setHeader('content-length', String.valueOf(caseAtt.body.size()));
    req.setHeader('accept-encoding', 'gzip, deflate, br');
    req.setHeader('Connection', 'keep-alive');
    req.setTimeout(120000);
    req.setEndpoint(endpoint);

    req.setBodyasBlob(caseAtt.body);

    try{
        Http http = new Http();
        HttpResponse res = http.send(req);
        return res;
    }catch(CalloutException ex){
        system.debug('CalloutException: '+ex.getMessage());
        return null;
    }
    catch(Exception ex){
        system.debug('Exception: '+ex.getMessage());
        return null;
    }}

QUESTION

  1. Is there a limitation in SF for sending files larger than 100KB via HttpRequest (I found this article, but it is very old so I am not sure about it)?

  2. Is there a different approach for sending large files to a third party?

Posts I tried their solution but did not work:

3

0

You must log in to answer this question.

Browse other questions tagged .