image - iOS: How to use operation queues to download large amount of data? -
i developing ios application in have download large data images , videos locally on device. data can in gb's , there can thousands of files download. so, whats best way tackle situation. because can have many failures request time out etc.
also have updated core data if file has been downloaded or not.
any best , simple way appreciated.
you can use afnetworking that. best api dealing web services days .you can download latest afnetworking api ios github and.
you can use
- (void)uploadimageaturl:(nsurl*)url { afhttpclient *httpclient = [[afhttpclient alloc] initwithbaseurl:url]; nsdata *imagedata = uiimagejpegrepresentation([uiimage imagenamed:@"yourimg.jpg"], 0.5); nsmutableurlrequest *request = [httpclient multipartformrequestwithmethod:@"post" path:@"" parameters:nil constructingbodywithblock: ^(id <afmultipartformdata>formdata) { [formdata appendpartwithfiledata:imagedata name:@"yourimg" filename:@"yourimg.jpg" mimetype:@"image/jpeg"]; }]; afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; [operation setuploadprogressblock:^(nsuinteger byteswritten, long long totalbyteswritten, long long totalbytesexpectedtowrite) { //check progress nslog(@"sent %lld of %lld bytes", totalbyteswritten, totalbytesexpectedtowrite); }]; [httpclient enqueuehttprequestoperation:operation];
}
Comments
Post a Comment