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
Somya TiwariSomya Tiwari 

Sending files as MultiPart data in Salesforce

I am integrating with one of the provider who accepts a file to upload in their system. While doing so they require the file to be sent as multipart/form-data in the following format !! 

I tried configuring it as MultiPart form data using Base64 String still it is not working !! 

-H "accept: application/json"
-H "x-api-key: API_KEY" 
-H "x-api-token: API_TOKEN" 
-H "Content-Type: multipart/form-data" 
-F "file=@b4b35527-522d-4228-a266-bdaa80e28a8b.jpg;type=image/jpeg"
AnudeepAnudeep (Salesforce Developers) 
Hi Somya, 

I recommend reviewing the following example

POST Mutipart/form-data with HttpRequest


You can check these two article. 

Apex Code for Uploading Files Using Multipart/Form Data in Salesforce (

Upload file using multipart/form data from apex salesforce (

public class FileUploadController {
    public void uploadFile(String fileName, Blob fileData) {
        HttpRequest req = new HttpRequest();
        req.setEndpoint(''); // Replace with your desired endpoint URL
        String boundary = '----------------------------' + String.valueOf(System.currentTimeMillis());
        String header = '--' + boundary + '\r\nContent-Disposition: form-data; name="file"; filename="' + fileName + '"\r\nContent-Type: application/octet-stream\r\n\r\n';
        String footer = '\r\n--' + boundary + '--\r\n';
        String body = header + EncodingUtil.base64Encode(fileData) + footer;
        req.setHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
        req.setHeader('Content-Length', String.valueOf(body.length()));
        Http http = new Http();
        HttpResponse res = http.send(req);
        if (res.getStatusCode() == 200) {
            // File uploaded successfully
        } else {
            // Handle error response