gpt4 book ai didi

ios - 用于多部分表单上传的 AFNetworking 2.0 API

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:53 25 4
gpt4 key购买 nike

上传多部分表单的 AFNetworking 2.0 方法是什么,即使用 AFHTTPSessionManagerAFHTTPRequestOperationManager

这是一些 AFNetworking < 2.0 代码的示例:

[[ASAPIClient sharedClient] enqueueHTTPRequestOperation:[[ASAPIClient sharedClient] HTTPRequestOperationWithRequest:[[ASAPIClient sharedClient] multipartFormRequestWithMethod:@"POST" path:@"/some/url" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
if(_selectedPhoto.image)
{
NSData *imageData = UIImageJPEGRepresentation([_selectedPhoto image], 0.5);

[formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}
}] success:^(AFHTTPRequestOperation *operation, id responseObject) {

if([[responseObject objectForKey:@"result"]isKindOfClass:[NSDictionary class]] )
{

}

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

}]];

最佳答案

ASAPIManagerAFHTTPRequestOperationManager 的子类

[[ASAPIManager sharedManager] POST:@"/some/url" parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
if(_profileImageView.image){
[formData appendPartWithFileData:UIImageJPEGRepresentation(_profileImageView.image, 0.5) name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}
} success:^(AFHTTPRequestOperation *operation, id responseObject) {

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

}];

关于ios - 用于多部分表单上传的 AFNetworking 2.0 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19443241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com