AFNWorking(2.0)上传文件进度Progress

/**

*  上传文件

*

*  @param paramDic   附加post参数

*  @param requestURL 请求地址

*  @param fileData   上传的文件

*  @param success    上传成功回调

*  @param failure    上传失败回调

*  @param progress   实时上传进度回调

*/

+ (void)uploadFileWithOption:(NSDictionary*)paramDicrequestURL:(NSString*)requestURLfileData:(NSData*)fileDataprogress:(void(^)(floatprogress))progressuploadSuccess:(void(^)(idresponseObject))successuploadFailure:(void(^)(NSError*error))failure

{

AFHTTPRequestOperationManager*manager = [AFHTTPRequestOperationManagermanager];

AFHTTPRequestOperation*operation = [managerPOST:requestURLparameters:paramDicconstructingBodyWithBlock:^(id formData) {

[formDataappendPartWithFileData:fileDataname:@"file"fileName:@"filename.jpeg"mimeType:@"image/jpeg"];

}success:^(AFHTTPRequestOperation*operation,idresponseObject) {

success(responseObject);

}failure:^(AFHTTPRequestOperation*operation,NSError*error) {

failure(error);

}];

[operationsetUploadProgressBlock:^(NSUInteger bytesWritten,longlongtotalBytesWritten,longlongtotalBytesExpectedToWrite) {

floatp = (float)totalBytesWritten / totalBytesExpectedToWrite;

progress(p);

}];

}

你可能感兴趣的:(AFNWorking(2.0)上传文件进度Progress)