MBProgressHUD *HUD = [[MBProgressHUD alloc] init];
HUD.mode = MBProgressHUDModeAnnularDeterminate;//圆环作为进度条
HUD.labelColor = [UIColor whiteColor];
HUD.labelFont = [UIFont systemFontOfSize:13];
[HUD show:YES];
[self.view addSubview:HUD];
NSDictionary *dic = @{@"file":@"",@"wname":self.titleTextField.text,@"wdiscription":self.jianJieTextView.text};
AFHTTPRequestOperationManager* _manager = [AFHTTPRequestOperationManager manager];
NSMutableURLRequest* request = [_manager.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[NSString stringWithFormat:@"%@%@",URL_YUMING,SmallConnoisseur_updateWorks_URL] parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileData:UIImageJPEGRepresentation(self.imgView.image, 0.5) name:@"file" fileName:@"/Documents/pic.png" mimeType:@"image/png"];
} error:nil];
AFHTTPRequestOperation *operation = [_manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSLog(@"----成功---");
dispatch_async(dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
NSLog(@"---失败-");
HUD.labelText = @"上传失败";
[HUD hide:YES afterDelay:3];
}];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
NSLog(@"00----1---%ld----",bytesWritten);
NSLog(@"00----2---%lld----",totalBytesWritten);
NSLog(@"00----3---%lld----",totalBytesExpectedToWrite);
NSLog(@"00-------%f--",(float)totalBytesWritten/totalBytesExpectedToWrite);
HUD.progress = (float)totalBytesWritten/totalBytesExpectedToWrite;
if (HUD.progress > 0.9f) {
HUD.labelText = @"上传完成";
[HUD hide:YES afterDelay:3];
}else{
HUD.labelText = [NSString stringWithFormat:@"当前上传的进度为%.2f",(float)totalBytesWritten/totalBytesExpectedToWrite*100];
}
}];
[operation start];
ios AFNetWorking上传图片有进度条
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 公司数据存储选择使用七牛,七牛的提供的API的确很简单,方便客户使用。但是也有缺憾,当初使用的时候发现两个七牛的缺...
- 公司旧项目的网络请求类是afn 2.5版本的,在做文件上传的时候发现没有实时获取进度的那个自带方法,需要手动添加。...
- 1.GET - (void)testgetDemo { NSString *path = @"http://m.w...
- 3.POST上传图片到服务器 #pragma mark - post上传头像 - (void)postImageT...