Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用AFN网络上传多个图像或文件,_Ios_Objective C_Afnetworking - Fatal编程技术网

Ios 使用AFN网络上传多个图像或文件,

Ios 使用AFN网络上传多个图像或文件,,ios,objective-c,afnetworking,Ios,Objective C,Afnetworking,我想使用AFN网络上传多个图像。 像这样 我附上了邮递员的例子 我的代码: NSString *key = [[mediaInfo allKeys] objectAtIndex:0]; NSDictionary *dict = [[mediaInfo objectForKey:key] objectAtIndex:0]; UIImage *image = [dict objectForKey:IQMediaImage]; NSMutableDictionary *dictParam =

我想使用AFN网络上传多个图像。 像这样

我附上了邮递员的例子

我的代码:

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

AFHTTPSessionManager*manager=[AFHTTPSessionManager];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"multipart/form­data" forHTTPHeaderField:@"Content-Type"];

[manager POST:[NSString stringWithFormat:@"%@/api/1.0/customer/sign-up", DEFAULT_URL] parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {

if (userHaveImage == YES) {
    [formData appendPartWithFileData:image name:@"img_profile" fileName:@"profileImage.jpg" mimeType:@"image/jpg"];
    [formData appendPartWithFormData:image name:@"img_profile"];
}
manager.requestSerializer=[AFJSONRequestSerializer序列化程序]; [manager.requestSerializer设置值:@“多部分/表单数据”用于HttpHeaderField:@“内容类型”]; [manager POST:[NSString stringWithFormat:@“%@/api/1.0/customer/sign up”,默认\u URL]参数:参数constructingBodyWithBlock:^(id\u非空formData){ 如果(userHaveImage==YES){ [formData appendPartWithFileData:图像名称:@“img_profile”文件名:@“profileImage.jpg”mimeType:@“image/jpg”]; [formData appendPartWithFormData:图像名称:@“img_配置文件”]; }

然后将图像转换为UTF8字符串并以该格式发送。

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];

你的答案是对的。但我想问的是,我们可以直接传递图像吗?不转换数据。或者不传递图像URL。