How to change url when using NSURLSession downloadTaskWithResumeData :?

I use NSURLSession downloadTaskWithURL: to upload a file and use NSURLSessionDownloadTask cancelByProducingResumeData:to create NSDataand save it in a local temp file.

Then I want to resume downloading with NSURLSession downloadTaskWithResumeData:.

There is a problem, the URL that I used to download the file is temp url, I need to request a new URL to download the same file. After using downloadTaskWithResumeData:it, it helps me create NSURLSessionDownloadTaskwith the same URL as before.

How do I replace the URL with the new URL I am requesting recently? Or how can I change the HTTP request of this NSURLSessionDownloadTask?

How do you deal with a situation that resumes NSURLSessionDownloadTaskwith a different URL?

I am going to get the .tmp file downloaded NSURLSessionand set Range in the HTTP header and then write the new temp url to this file.

+4
source share
1 answer

I do not believe that we can resume the download if the path to the resource has been changed.

According to the Apple developer class reference:

Download can only be resumed under the following conditions:

  • Resource has not changed since its first request

  • The challenge is an HTTP or HTTPS GET request

  • The server provides either an ETag header or Last-Modified (or both) in its response

  • Server supports byte range requests

  • The temporary file was not deleted by the system in response to disk pressure

, , URL . .

0

Source: https://habr.com/ru/post/1607588/


All Articles