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];
网友评论