How to upload a big file with AsiHttpRequest
I use ASIFormDataRequest to upload my file to server.
I convert the file to a NSData object first. But when my file is bigger than 2M, my app always down in upload process.
I know it is a memor开发者_如何学JAVAy issue. But I don't know how to fix it.
Thanks!
You don't have to convert to NSData. You can directly set the file as post value.
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];
Or
[request setFile:@"/Users/ben/Desktop/ben.jpg" withFileName:@"myphoto.jpg" andContentType:@"image/jpeg" forKey:@"photo"];
If you are uploading large files I would suggest you to use a UIProgressIndicator so you keep the user in the loop about the progress.
To learn more about ASIHTTPRequest see How to use.
Hope this solves your issue.
Cheers
精彩评论