I'm presently using the mobile SDK with native iOS to download VersionData of content objects thus:

SFRestRequest *request = [[SFRestRequest alloc] init];

request.endpoint = @"services/data/v28.0/sobjects/ContentVersion/";
request.method = SFRestMethodGET;
request.path = [NSString stringWithFormat:@"%@/VersionData",contentVersionId];
request.parseResponse = NO;

[request setAccessibilityLabel:[[NSString alloc] initWithFormat:@"%d", roReadDoc]];

[[SFRestAPI sharedInstance] send:request delegate:_delegate];

This works well on LTE with PDFs of reasonable size (a few MB). However with larger MP4s, I seem to encounter timeout issues.

Is there a better way to download VersionData ie. chunked or streamed, using the API?

Another issue I have is simply that the MP4 will not play in either a UIWebView or MPMoviePlayerController. I have read the following links, which seem to describe my issue, but haven't found an answer yet as to why MP4s from Salesforce seem to be in the incorrect format, or otherwise incompatible. Any idea? Thanks!

Video hosted on Content Documents

View MP4 files on iPad

Edit added: after further investigation it appears to me that a legacy app we are using seems to get this working using an http call in the format


| improve this question | | | | |

On VersionData: are you not attempting to download the full document with this request? I don't think this is what SFRestRequest is intended for. Given that you do not necessarily know in advance the size of the document, I think you'd be much better served by streaming directly to disk rather than trying to load the entire document in memory.

On media playback: Have you set the allowsInlineMediaPlayback (default NO) and mediaPlaybackRequiresUserAction (default YES) properties in your UIWebView?

| improve this answer | | | | |
  • I am able to check ContentSize in advance. I can see your point for not using memory when the files start to get huge. I'm thinking I may need to write some Apex to return chunks of around max 4-5MB at a time, and put the file together again on the iPad. Higher no. of API calls that way though. When I try to download files around 10MB then it seems Salesforce locks out my app for about 25 minutes, I start getting "Request timed out" on all subsequent requests, of all kinds. I'm using iPad so allowsInlineMediaPlayback is YES by default. Will check out mediaPlaybackRequiresUserAction. – Brad Thomas Jul 16 '14 at 14:18
  • I'm not sure I see how Apex would help here? Surely you'd hit a governor limit in Apex when loading the full file into memory? I meant that I would write my own network request (perhaps NSURLConnection rather than SFRestRequest) to stream the file directly to disk, which would also let you indicate download progress to the user. And I'm pretty sure the default value of allowsInlineMediaPlayback does not depend on your hardware; you will still need to set it to YES. – Jonathan Hersh Jul 16 '14 at 14:52
  • A lot of my MP4s run around 100MB, the largest is about 250MB. I see what you mean about hitting Apex limits. Its not immediately clear to me how to use NSURLConnection in the context of Salesforce Mobile SDK, I guess I'd basically have to build my own URL to call out to, including the auth part. Not sure that would resolve my problem with getting locked out either? I'm not clear why that is happening. Maybe because SFRestRequest hits the 3MB Apex response limit? Guess I just need to try NSURLConnection and see. Thanks for the idea. – Brad Thomas Jul 17 '14 at 19:16
  • You already have the URL (you know the user's instance and you know the content ID), but yes, you'll need to import the authorization headers into your NSURLConnection request from the SDK. And yes, my guess is that you're getting locked out because SFDC is hitting a processing time or memory limit and/or views your request as a DDOS in progress. – Jonathan Hersh Jul 17 '14 at 20:53
  • Also, the mobile SDK's networking bits are really just a fancy wrapper around MKNetworkKit, which is itself just a fancy wrapper around NSURLConnection. I'm sure you could extract some of the relevant code. – Jonathan Hersh Jul 17 '14 at 21:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.