ios - AFNetworking 2.3.1 上传图片 服务器无法接收到图片?
阿神
阿神 2017-04-17 13:06:20
0
5
815

我使用的最新版本的AFNetworking 2.3.1 该版本已经没有AFHttpClient这个类了 于是使用wiki中的这种方式上传图片

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
UIImage *image = [UIImage imageNamed:@"xxxx"];
[manager POST:@"http://example.com/resources.json" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    [formData appendPartWithFileData:UIImagePNGRepresentation(image)
                                    name:@"avatar"
                                fileName:@"avatar.png"
                                mimeType:@"image/png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

但是服务器一直接受不到图片数据。这里的name与filename参数有什么要求吗?

阿神
阿神

闭关修行中......

reply all(5)
小葫芦

name:@"avatar"
This field must be consistent with the server

Peter_Zhu

Replace fileName with filePath, for example fileName:filePath, provided that the data is read from a file

大家讲道理

Is the problem solved? Please reply if you see it, I want to know too!

迷茫

Please answer! Thank you

阿神

Server side: file.getFile("avatar");

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template