iOS Resumable Uploads Troubles

I am referencing: https://developer.apple.com/documentation/foundation/pausing-and-resuming-uploads

Specifically:

You can’t resume all uploads. The server must support the latest resumable upload protocol draft from the HTTP Working Group at the IETF. Also, uploads that use a background configuration handle resumption automatically, so manual resuming is only needed for non-background uploads.

I have control over both the app and the server, and can't seem to get it to work automatically with a background url session. In other words, making multiple requests to get the offset then upload, easy but I am trying to leverage this background configuration resume OS magic.

So anyone know what spec version does the server/client need to implement? The docs reference version 3, however the standard is now at like 11. Of course, I am trying out 3.

Does anyone know how exactly this resume is implemented in iOS, and what exactly it takes care of? I assumed that I can just POST to a generic end point, say /files, then the OS receives a 104 Location, and saves that. If the upload is interrupted, when the OS resumes the upload, it has enough information to figure out how to resume from the exact offset, either by making a HEAD request to get the offset, or handle a 409. I am assuming it does this, as if it doesn't, the 'uploads that use a background configuration handle resumption automatically' is useless, if it just restarts from 0.

Note, of course making individual POST/HEAD/PATCH requests manually works, but at that point I'm not really leveraging any OS auto-magic, and am just consuming an API that could really implement any spec. This won't work in the background, as the OS seems to disallow random HTTP requests when it wakes the app for URLSession background resumes.

As of right now, I have it 'partially' working, insofar as the app does receive the 104 didReceiveInformationalResponse url delegate call, however it seems to then hang; it stops sending bytes, seemingly when the 104 is received. However, the request does not complete. In other words, it doesn't seem to receive a client timeout or otherwise indicate the request has finished.

Right now, I am starting a single request, POSTing to a /files end point, i.e. I am not getting the location first, then PATCHing to that, as if I do that, the OS 'automatic' resuming fails with a 409, i.e. it doesn't seem to make a HEAD request and/or use the 409 offset correction then continue with the PATCH.

Any idea what could be going on?

That’s an amazing question where I would love to invite experts of that implementation here as I know how difficult is to implement that o a URLSession that will match on the server to make it resumable. I’m not an expert but this question requires an expert to go over the documentation you need to have a successful implementation.

Because the implementation of IETF draft that was actively evolving, the auto-magic requires your server to perfectly match a frozen-in-time version of that draft, down to the exact HTTP framing looks like as I’m going over the documentation.

I was educating myself on the IETF draft is now much further along. However, the implementation is hardcoded to look for the 104 informational response. If you want the OS auto-magic, your server must implement the Draft 03 behavior, if I read it correctly.

The resumable upload protocol is currently under development and standardization efforts within the IETF. This protocol enables robust and resumable file transfers, allowing applications to pause and resume uploads even after network interruptions.

https://www.ietf.org/archive/id/draft-ietf-httpbis-resumable-upload-01.html

When you use a background URLSession configuration, the networking is handed off. I was looking at this video talking about that:

https://developer.apple.com/videos/play/wwdc2017/504/

If you manually get the location and start the background session with a PATCH, nsurlsessiond treats it as a standard, non-resumable request. I believe this is the way to take care in the client the recover for a failed upload https://developer.apple.com/documentation/foundation/pausing-and-resuming-uploads#Recover-a-failed-upload

Is your app receiving the URLSession:task:didReceiveInformationalResponse: delegate callback with the 104 but then hangs and stops sending bytes?

Looking forward to see other developers opinions on this awesome subject.

Albert Pascual
  Worldwide Developer Relations.

iOS Resumable Uploads Troubles
 
 
Q