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
Sameer Rath 4Sameer Rath 4 

HTTP request for Upload a File

Hi all,
I am learning box integration and facing some problem in uploading files to box. What should be the HTTP request to be set for uploading a file in box ?
Can any body please help me out. 

Thank You.
Gaurav KheterpalGaurav Kheterpal
Try this example code, it should work uploading to your Box account.
public static HTTPResponse uploadFile(Attachmnet file)

  String boundary = '__boundary__xxx';
  String header = '--'+boundary+'\n';
     + 'Content-Disposition: form-data; name="data"; filename="'
     +'"\nContent-Type: application/octet-stream\n\n';
  String footer = '\n--'+boundary+'--';
  String body = EncodingUtil.base64Encode(file.Body); //encodes the blob into a base64 encoded String body = header + body + footer;
  HttpRequest req = new HttpRequest();
  req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);

  Http http = new Http();
      return http.send(req);

Check the link i am sure it will help u

Sameer Rath 4Sameer Rath 4
Hi Gaurav,
Still problem has not solved. Its showing 405 error. [System.HttpResponse[Status=Method Not Allowed, StatusCode=405] ]