我使用AFNetworking将图像上传到服务器.http响应表示图片上传成功。但是在服务器上找不到该文件。似乎服务器无法保存我上传的图像。图像来自UIImagePicker。这是我的代码
+ (void)httpUploadJPGImageWithParam:(NSDictionary *)param path:(NSString *)path image:(UIImage*)image success:(SucceedBlock)successBlock failed:(Fail)failedBlock
{
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:path parameters:param constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:imageData name:@"image"];
//[formData appendPartWithFileData:imageData name:@"image" fileName:@"photo.jpg" mimeType:@"image/jpeg"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
successBlock(responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if (failedBlock) {
failedBlock([error localizedDescription]);
}
}];
}
答案 0 :(得分:0)
在没有看到服务器代码的情况下很难分辨,但通常你会使用
- (void)appendPartWithFileData:(NSData *)data
name:(NSString *)name
fileName:(NSString *)fileName
mimeType:(NSString *)mimeType;
通常在使用多部分请求上传文件时(例如,在PHP中由$_FILES
解析),它也期待文件名和mime类型。