0

I am having an issue specifically trying to upload an attachment blob to Egnyte using the REST API. Code is below. Any input is appreciated, I am guessing my POST is missing something but I can't see it.

Attachment att = [SELECT Body FROM Attachment WHERE Id = '00P55000001p7tE'];

String destinationPath = 'pubapi/v1/fs-content/Shared/Salesforce.com/Accounts/Amy%20Test/Opportunities/Amy%20Test%20no%20MgmtCo/Test/test';

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setBodyAsBlob(att.Body);
req.setHeader('Authorization', 'Bearer ' + authResponse.access_token);

req.setEndpoint('callout:EgnyteDerrickCredential/' + destinationPath);
HttpResponse res = h.send(req);

System.Debug(res.getBody());

With response:

18:55:56:582 USER_DEBUG [53]|DEBUG|{"message":"content length do not match with DB object size for workgroupid:65a17409-23cc-4f04-baf6-00f5cbecbb6d and objectId: 157.9c1ce840-b63c-4609-9204-10548c617015 actual size: 0, expected size: 55456"}

2 Answers 2

0

There seems to be an issue with the Salesforce library that you are utilizing setting an incorrect value for the content-length header. Thus, the request is unable to upload the file. Our development team is looking into the issue now and will have an update soon.

Thanks.

Cara de Freitas Bart (Associate Product Manager at Egnyte)

2
  • Below is the code which uploads attachment in Salesforce. Please change the record id and endpoint on your end and then try it. Jun 28, 2016 at 15:47
  • Attachment attach = [Select Id, Name, Body, ContentType from attachment where ID = '00P24000000tVl8']; HttpRequest req = new HttpRequest(); req.setEndpoint('mydomain.egnyte.com/pubapi/v1/fs-content/Shared/Documents/…); req.setHeader('Authorization','Bearer YOUR_TOKEN'); req.setHeader('Content-Type',attach.ContentType); req.setMethod('POST'); req.setBodyAsBlob(attach.body); Http http=new Http(); HttpResponse res=http.send(req); System.debug('response -- >'+res.getBody()); Jun 28, 2016 at 15:47
0

I needed to specify the content-type with the header before sending. That fixed the issue.

req.setHeader('Content-Type', 'application/octet-stream');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .