gpt4 book ai didi

ios - 使用 AFNetworking 上传多个图像或文件,

转载 作者:行者123 更新时间:2023-12-01 19:43:42 27 4
gpt4 key购买 nike

我想使用 AFNetworking 上传多张图片。
像这样 Please Check This Image

我附上了 postman 的例子。

我的代码:

NSString *key = [[mediaInfo allKeys] objectAtIndex:0];
NSDictionary *dict = [[mediaInfo objectForKey:key] objectAtIndex:0];
UIImage *image = [dict objectForKey:IQMediaImage];

NSMutableDictionary *dictParam = [[NSMutableDictionary alloc] init];
[dictParam setValue:imageData forKey:@"Files"];

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:@BaseURL(@"/MediaUpload") parameters:dictParam progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { }];

AFNetworking 3.0

最佳答案

AFURLSessionManager 检查此方法:

- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
fromFile:(NSURL *)fileURL
progress:(void (^)(NSProgress *uploadProgress)) uploadProgressBlock
completionHandler:(void (^)(NSURLResponse *response, id responseObject, NSError *error))completionHandler

完整代码实现:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *sessionManager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];

[[sessionManager uploadTaskWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@BaseURL(@"/MediaUpload")]]
fromFile:[NSURL fileURLWithPath:@"/path/to/uploading_file"]
progress:^(NSProgress * _Nonnull uploadProgress) { }
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
}] resume];

关于ios - 使用 AFNetworking 上传多个图像或文件,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51706640/

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