Re: NSURLSessionUploadTask and resuming
Re: NSURLSessionUploadTask and resuming
- Subject: Re: NSURLSessionUploadTask and resuming
- From: Jens Alfke <email@hidden>
- Date: Tue, 08 Sep 2015 18:00:13 -0700
> On Sep 8, 2015, at 4:05 PM, James Gale <email@hidden> wrote:
>
> What I would like to know is there a way to make the NSURLSessionUploadTask start from an offset of the file (such as setting a range header), or getting the NSURLSessionUploadTask with stream to allow me to send a content length?
It doesn’t look like it, from the API and the comments in it: "An NSURLSessionUploadTask does not currently provide any additional functionality over an NSURLSessionDataTask.” It’s missing the -cancelByProducingResumeData: method of NSURLSessionDownloadTask.
Probably this is because (as far as I know) it’s uncommon for a server to support byte-range PUTs, partly because it would be really problematic. To resume a PUT you’d have to GET the resource to find out how many bytes made it through, then send another PUT containing all the remaining data, with a Range header specifying a range starting at the first missing byte. The weird part is that if the server doesn’t support Range: with a PUT, it might just ignore the header, which means you’ll replace the entire resource with the remaining data, resulting in a bad upload, without getting any error. There’s also no way to detect whether another client also wrote to that resource in the meantime (i.e. using eTags) so it’s possible to end up with a mix of your data and someone else’s.
Assuming your server does support this, I think you’ll have to implement the upload using the lower-level NSURLSessionStreamTask, and setting and checking HTTP headers yourself. (This is assuming the server even supports byte-ranges on a PUT request.)
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden