Custom Integration with Salesforce
I am trying to upload a file to Box using following apex method.
public static String uploadBoxSample(){
/* endpoint by named credential */
HttpRequest request = new HttpRequest();
request.setHeader('Content-Type','multipart/form-data');
request.setMethod('POST');
String endpoint = 'callout:uploadBox/api/2.0/files/content';
request.setEndpoint(endpoint);
BodyJson body = new BodyJson ();
body.attributes.content_created_at ='';
body.attributes.content_modified_at ='';
body.attributes.name = 'testTextFile.txt';
body.attributes.parent.id = '0'; // parent should be object
body.file = 'test file content';
String strBody = System.JSON.serialize(body);
request.setBody(strBody);
Http http = new Http();
HttpResponse response = http.send(request);
System.debug('response body ' + response.getBody());
return null;
}
public class BodyJson {
Attributes attributes;
String file;
public BodyJson(){
attributes = new Attributes();
}
}
public class Attributes {
public String content_created_at;
public String content_modified_at;
public String name;
public parent parent;
public Attributes(){
parent = new parent();
}
}
public class parent {
public String id;
}
I got following error.
code : bad_request, status : 400, message : the request was rejected because no multipart boundary was found
Thanks for any solution.
-
正式なコメント
Hey Lin,
Yes you have to add a boundary to the call. Did you get around the size limitations?
Thanks,
Alex, Box Developer Advocate
コメントアクション
サインインしてコメントを残してください。
コメント
2件のコメント