You need to sign in to do that
Don't have an account?
How to Upload a word document using Rest AP
Hi
I want to upload a word document on Box( External Storage) using Rest API calls .
I am encoding the body in base 64 using Encoding util class but on box the content of uploaded file is in encrypted form .
Is there any other way to send the word /ppt docs so that the content dont get encrypted on Box( External Storage) ?
private HttpResponse UploadFile(){
Document Doc =[Select Body, BodyLength, Id, Name, Type, ContentType From Document ];
System.debug('Doc' + Doc);
String p_fileName =doc.Name+'.'+doc.Type;
String parent_id = '1121945745';
String boundary = 'AaBbCcX30';
String content = 'Content:\r\n--' + Boundary + '\r\n'+'Content-Disposition: form-data; name="files";filename="'+p_fileName+ '"\r\n'+ 'Content-Type:'+doc.ContentType+'\r\n\r\n';
content += '\r\n'+EncodingUtil.base64Encode(Doc.Body)+'\r\n';
content +='--' + Boundary +'\r\n'+'Content-Disposition: form-data; name="parent_id"'+'\r\n\r\n'+'0'+'\r\n' ;
content+= '--' + Boundary + '--\r\n' ;
Http h = new Http();
HttpRequest req = new HttpRequest();
string sUrl = 'https://upload.box.com/api/2.0/files/content';
req.setHeader('Authorization', 'Bearer ' + accessToken);
req.setHeader('Content-Type','multipart/form-data;boundary='+boundary);
req.setHeader('Content-Encoding','base64');
req.setEndpoint(sUrl);
req.setMethod('POST');
req.setBody(content);
HttpResponse res;
if(!Test.isRunningTest()){
res = h.send(req);
}
else{
res = new HttpResponse();
}
valuetoShow = 'Get Doc: ' + res.getBody();
return res;
}