0

I'm attempting to upload a file (VersionData from ContentVersion) to OneDrive using the Graph API Resumable Upload Method:

https://dev.onedrive.com/items/upload_large_files.htm

I'm able to create the upload session:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "uploadUrl": "https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337",
  "expirationDateTime": "2015-01-29T09:21:55.523Z",
  "nextExpectedRanges": ["0-"]
}

And I'm stuck on how to upload the fragments: https://dev.onedrive.com/items/upload_large_files.htm#upload-fragments

I presume the problem is I don't have Binary Stream and only have access to blobs. I am uncertain of what to set the body too.

That would explain the requirements for "bytes" in the content length, correct?

Here is what I have for my APEX Code connecting to the REST service

webRequest.setEndPoint(uploadSession);
webRequest.setHeader('Authorization', 'Bearer ' + getAccessToken());
webRequest.setHeader('Content-Type', 'application/json');
webRequest.setHeader('Accept', 'application/json');
webRequest.setHeader('Host', 'graph.microsoft.com');
webRequest.setHeader('Content-Length', '681');
webRequest.setHeader('Content-Range', 'bytes 0-');
webRequest.setMethod('PUT');
webRequest.setBody(EncodingUtil.base64Encode(content[0].versiondata));

HttpResponse webresponse = new HttpResponse();
webresponse = http.send(webRequest);

That body is likely incorrect.

  • breaking blobs apart into fractional blobs isn't possible and even if it were, you might blow up heap ( 12 MB max for async transaction). – cropredy Jul 16 '17 at 23:14
  • could I break them into a byte-array? If I could do files less than 4MB it would still be a massive win. Also, is the heap size for an individual call or collectively throughout the Org? – tjcinnamon Jul 17 '17 at 21:11
  • 1
    heap size is per transaction. files less than 4MB you could do as one callout to that service (which has a 60MB limit before chunking is required). Other solutions involve using systems that can read from SFDC and are not bound by the heap and thus they can fetch giant files via SFDC API and break apart using whatever tools avail on those sys. Your sys would need to signal to outside sys with id of Contentversion – cropredy Jul 18 '17 at 1:37
  • For the files under 4MB scenario: sfdc stores them as blobs and the REST MS Graph upload service is looking for a ByteStream (bytearray?). How do I get those blond in the correct format? – tjcinnamon Jul 18 '17 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.