Asihttprequest-Breakpoint continued to need the original site support!

Source: Internet
Author: User

Ext.: http://zyc-to.blog.163.com/blog/static/17152400201110221114526/

Starting with version 0.94, ASIHTTPRequest can resume interrupted downloads

12345678910111213141516171819 - (IBAction)resumeInterruptedDownload:(id)sender{  NSURL*url = [NSURLURLWithString:    @"http://www.dreamingwish.com/wp-content/uploads/2011/10/asihttprequest-auth.png"];  ASIHTTPRequest *request = [ASIHTTPRequestrequestWithURL:url];  NSString*downloadPath = @"/Users/ben/Desktop/asi.png";  //当request完成时,整个文件会被移动到这里  [requestsetDownloadDestinationPath:downloadPath];  //这个文件已经被下载了一部分  [requestsetTemporaryFileDownloadPath:@"/Users/ben/Desktop/asi.png.download"];  [requestsetAllowResumeForFileDownloads:YES];  [requeststartSynchronous];  //整个文件将会在这里  NSString*theContent = [NSString stringWithContentsOfFile:downloadPath];}

This feature is only valid for downloading data to a file, you must set allowresumeforfiledownloads to Yes for the request of the situation:

    • Any download that you would like to be able to resume in the future (otherwise, ASIHTTPRequest will delete the temporary file when the memory is canceled or freed)
    • Any download you want to continue with the breakpoint

In addition, you must set a temporary download path (settemporaryfiledownloadpath), which is the path to the incomplete data. The new data will be added to this file, and when the download is complete, the file will be moved to Downloaddestinationpath .

The continuation of the breakpoint works by reading the size of the Temporaryfiledownloadpath file and using the range:bytes=x HTTP header to request the remaining file contents.

ASIHTTPRequest does not detect the presence of a accept-ranges header (because additional head-header requests consume additional resources), so this feature is used only if the server is determined to support the continuation of a breakpoint download.

Asihttprequest-Breakpoint continued to need the original site support!

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.