AFNetworking 2.3.1 上传图片 服务器无法接收到图片?


我使用的最新版本的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参数有什么要求吗?

ios afnetworking2.0 iphone

up主是大好人 10 years, 4 months ago

fileName后面用filePath代替,例如 fileName:filePath,前提是数据是从文件读入的

幻♂想♂乡 answered 10 years, 4 months ago

name:@"avatar"
这个字段要跟服务器一致

天地君亲师 answered 10 years, 4 months ago

Your Answer