使用 ASIFormDataRequest uiprogressview 跳转到 99% 然后 100%
我正在尝试实现一个用于图像上传的 UIProgressView,所以我将其设置为
uploadProgress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
[uploadProgress setFrame:CGRectMake(85, 19, 150, 9)];
imageRequest = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://theurl.com"]];
[imageRequest setDelegate:self];
[imageRequest setDidFinishSelector:@selector(uploadedImage:)];
[imageRequest setDidFailSelector:@selector(asiRequestFailed:)];
[imageRequest setTimeOutSeconds:60];
[imageRequest addData:imgData forKey:@"file"];
[imageRequest addPostValue:[parameters yajl_JSONString] forKey:@"json"];
[imageRequest setUploadProgressDelegate:uploadProgress];
[imageRequest setShowAccurateProgress:YES];
[imageRequest startAsynchronous];
加载一段时间,然后跳到几乎 100%,然后达到 100%,然后几秒钟后,它完成。我的代码中是否缺少某些内容,或者我需要在服务器端执行某些操作?
谢谢
I'm trying to implement a UIProgressView for an image upload so I set it up with
uploadProgress = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
[uploadProgress setFrame:CGRectMake(85, 19, 150, 9)];
imageRequest = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:@"http://theurl.com"]];
[imageRequest setDelegate:self];
[imageRequest setDidFinishSelector:@selector(uploadedImage:)];
[imageRequest setDidFailSelector:@selector(asiRequestFailed:)];
[imageRequest setTimeOutSeconds:60];
[imageRequest addData:imgData forKey:@"file"];
[imageRequest addPostValue:[parameters yajl_JSONString] forKey:@"json"];
[imageRequest setUploadProgressDelegate:uploadProgress];
[imageRequest setShowAccurateProgress:YES];
[imageRequest startAsynchronous];
It loads for awhile, then jumps to almost 100% then it gets to 100%, then after a couple seconds, it completes. Is there something I'm missing in my code, or do I need to do something on the server side?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跟踪 Post 操作总是会遇到这个问题。数据上传,然后您的应用程序必须等待服务器的响应,表明它已成功完成。 ASIFormDataRequest 知道数据的增量发送,因此它可以准确地跟踪此进度,直到发送最后一位数据。但是,它无法知道您的服务器需要多长时间来响应以确认整个上传已成功接收(当您的 didFinishSelector 被调用时)。您的上传速度很快,进度跟踪高达 99%,然后一直保持在 99%,直到调用 uploadImage,这表明它已完成,即 100%。
Tracking a Post operation is always going to have this issue. The data uploads, and then your app has to wait for the response from your server that it has completed successfully. The ASIFormDataRequest is aware of the incremental sending of data, so it can track this progress accurately up until the last bit of data is sent. It can't however, know how long your server will take to respond to confirm that the entire upload has been received successfully (when your didFinishSelector is called). Your upload is fast, and progress is tracked up to 99%, then sits at 99% until uploadImage is called, which signals it's completion, 100%.