AFNetworking封装上传文件
作者:
Crassus | 来源:发表于
2020-01-17 17:38 被阅读0次
AFNetworking版本
AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
[session POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
NSData *data = [NSData dataWithContentsOfFile:filePath];
[formData appendPartWithFileData:data name:@"logfile" fileName:filePath.lastPathComponent mimeType:@"text/plain"];
} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable resp) {
BOOL result = false;
if (resp[@"code"] && [resp[@"code"] intValue] == 0) {
result = true;
}
if (completion) {
completion(result);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (completion) {
completion(false);
}
}];
本文标题:AFNetworking封装上传文件
本文链接:https://www.haomeiwen.com/subject/vqqhzctx.html
网友评论