I have a requirement where I am supposed to send files from Salesforce via an API Call. I have been able to successfully send PDF Files, but the same is not happening for other file formats, like Tiff, JPEG, PNG format files.

The same request is established on POSTMAN Tool, and the same files are being successfully being sent, but from Apex, that is not happening.

The file is manipulated is the following manner, and sent via API Request.

String filename = fileTitle+'.'+docType;
            System.debug('filename' +filename);
            String header = '\n--' + boundary + '\nContent-Disposition: form-data; name="file"; filename="' + fileName + '"\nContent-Type: application/octet-stream\n\n' ;
            system.debug('Header '+header);
            header = EncodingUtil.base64Encode(Blob.valueOf(header+'\n\n'));
            String footer = '--' + boundary + '--'; 
            footer = '\r\n' + footer;
            system.debug('footer '+footer);
            footer = EncodingUtil.base64Encode(Blob.valueOf(footer));
            //header = header+'\r\n\r\n';
            string body ='';
                system.debug('In try');
                body = image;
                system.debug('Body '+body);
                body = header+body+footer;

Can anyone please advise.

Your Answer

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

Browse other questions tagged or ask your own question.