开发者

iPhone upload image speed advice

I have an app that allows you to take a picture, adjust the jpeg quality size (10-100%) and then send it to a server using ASIFormDataRequest (part of the ASIHTTPRequest implementation). This works fine over a network connection, but over the celluar network it appears to sit there for 5-10 minutes attempting to transmit the image post data, before failing (even with the quality at 10%).

On comparing this to the image uploads that the Twitter and Facebook apps provide (which take ~30 seconds to a minute) this isn't exactly ideal. I wondered if anyone could give me any advice about either how to speed up my data transfer, or monitor it so I can see exactly where the problem lies.

Once I get back to my mac laptop tonight I'll post a code snippet of exactly what it is I'm doing, in case that helps.

EDIT: Heres the code snippet:

NSURL *url = [NSURL URLWithString:@"...upload.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
NSString *fileName = [NSString stringWithFormat:@"%d", time];
...
float compressionRate = [userAccountView getCompressionRate];
NSLog(@"Compression rate: %.1f", compressionRate);
NSData *imageData = UIImageJPEGRepresentation(imageForView, compressionRate);
[request setData:imageData withFileName:fileName andContentType:@"image/jpeg" forKey:@"userfile"];
[request setDelegate:self];
[request startAsynchronous];

The .. code comment is where I just stick an 'uploading' image over the view. I suppose I could make the call synchronous as opposed to asynchronous, do you think that may improve performance? I have left it that way in case at a later stage I wanted to allow the user to do other bits while it is uploading.

Any advice would be great :)

Thanks,

Dan

EDIT:

Jesse, thanks for the comment - I added in [request setUploadProcessDelegate:self] and put in the required method to monitor the data that was being sent, and it all seemed to be sending okay.

JosephH - I have added in "[ASIHTTPRequest setShouldThrottleBandwidthForWWAN:YES]" as suggested, and have also added "set_time_limit(0);" into the PHP upload script (in case of timeouts) and now the data does seem to be sending and being retrieved over the cellular network, so horray! Am playing around now with file compressions etc. to find the best one for the best quality. ATM it seems like 0.3 is pretty good quality, and transfers in roughly 30 seconds or so, which is what I was开发者_StackOverflow社区 looking for!

I was also incorrectly setting the compression rate, as I was using 10-100 as opposed to 0.0-1.0, so I have also corrected that.

Thanks for your quick help guys in solving my issue!!


I think the first thing to do is to check what size the data you're sending is:

 NSLog(@"imageData size = %d", [imageData length]);

Does your NSLog correctly show the compressionRate is set to 0.1 for 10%?

ASIHTTPRequest also has a lot of debug logging you can enable - see ASIHTTPRequestConfig.h; just change everything from 0 to 1. It may not reveal anything of interest, but it is certainly worth looking at.

Are you calling [ASIHTTPRequest setShouldThrottleBandwidthForWWAN:YES] ?

When it fails, how does it fail, what is the error, what does any logging on the server show?

(If you find out anything extra, please do edit it into the question and post a comment and I'll take another look)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜