base64
NSMutableDictionary *paraDic = [[NSMutableDictionary alloc]init];
[paraDic setObject:[@"data:img/jpg;base64," stringByAppendingString:[_imageData base64EncodedString]] forKey:@"data"];
[paraDic setObject:@"tmp" forKey:@"filename"];
[paraDic setObject:@(_imageData.length) forKey:@"size"];
文件
NSData *data = UIImageJPEGRepresentation(image, 0.9);
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager POST:@"https://sm.ms/api/upload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
[formData appendPartWithFileData:data name:@"smfile" fileName:@"temp" mimeType:@"image/jpg"];
} progress:^(NSProgress * _Nonnull uploadProgress) {
NSLog(@"%f", uploadProgress.fractionCompleted);
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
网友评论