//上传头像
-(void)sendPersonIcon:(NSData*)imgData Authorization:(NSString*)authorization{
NSDictionary*dict=@{@"authorization":authorization};
// [self post:User_Avatar_Photo params:dict];
NSLog(@"%@",authorization);
AFHTTPSessionManager *manager=[AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",
@"text/html",
@"image/jpeg",
@"image/png",
@"application/octet-stream",
@"text/json",
@"multipart/form-data",
@"text/plain",
@"text/javascript",
nil];
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager.requestSerializersetValue:[NSStringstringWithFormat:@"Bearer %@",authorization]forHTTPHeaderField:@"Authorization"];
[managerPOST:@"http://223.223.200.50:8081/v1/user/photo" parameters:dict constructingBodyWithBlock:^(id _Nonnull formData) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat=@"yyyyMMddHHmmss";
NSString*str = [formatterstringFromDate:[NSDatedate]];
NSString*fileName = [NSStringstringWithFormat:@"%@.png", str];
[formDataappendPartWithFileData:imgData name:@"photo" fileName:fileName mimeType:@"image/png"];
}progress:^(NSProgress*_NonnulluploadProgress) {
//打印上传进度
CGFloatprogress =100.0* uploadProgress.completedUnitCount/ uploadProgress.totalUnitCount;
NSLog(@"打印:图片上传中....%f",progress);
}success:^(NSURLSessionDataTask*_Nonnulltask,id _NullableresponseObject) {
self.callBackBlock(YES,nil);//回调
}failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
self.callBackBlock(NO,error);//回调
}];
}
网友评论