IOS development ASIHTTPRequest breakpoint resume (download)

Source: Internet
Author: User

This article introduces the content of ASIHTTPRequest breakpoint resume (download) for iOS development, including ASIHTTPRequest can resume interrupted downloads and set a temporary download path, the working principle of resumable upload and so on.

From version 0.94, ASIHTTPRequest can resume interrupted downloads.

This feature is only valid for downloading data to files. You must set allowResumeForFileDownloads to YES for the following request:

  • Any download that you want to resume in the future. Otherwise, ASIHTTPRequest will delete the temporary files when canceling or releasing the memory)
  • Any download for resumable upload

In addition, you must set a temporary download path setTemporaryFileDownloadPath), which is the path of unfinished data. New data will be added to this file. When the download is complete, the file will be moved to downloadDestinationPath.

 
 
  1. -(IBAction) resumeInterruptedDownload :( id) sender
  2. {
  3. NSURL * url = [NSURL URLWithString:
  4. @ Http://www.dreamingwish.com/wp-content/uploads/2011/10/asihttprequest-auth.png];
  5. ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL: url];
  6. NSString * downloadPath = @ "/Users/ben/Desktop/asi.png ";
  7. // When the request is complete, the entire file will be moved here
  8. [Request setDownloadDestinationPath: downloadPath];
  9. // This file has been downloaded.
  10. [Request setTemporaryFileDownloadPath: @ "/Users/ben/Desktop/asi.png. download"];
  11. [Request setAllowResumeForFileDownloads: YES];
  12. [Request startSynchronous];
  13. // The entire file will be here
  14. NSString * theContent = [NSString stringWithContentsOfFile: downloadPath];
  15. }

The principle of resumable upload is to read the file size of temporaryFileDownloadPath and request the remaining file content using the Range: bytes = x HTTP header.

ASIHTTPRequest does not check whether the Accept-Ranges header exists. Because the additional HEAD header request consumes additional resources, this feature is used only when the server determines that resumable download is supported.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.