我正在尝试在服务器上传图像,并从服务器收到意外的响应。
以下是我正在使用的代码:
NSString *urlstring=[NSString stringWithFormat:USER_IMAGE_UPLOAD_URL_STRING];
NSData *imageData = UIImagePNGRepresentation(image);
int userId = self.request.userId;
NSString *imageName = [NSString stringWithFormat:@"%d.jpg",userId];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setObject:[NSNumber numberWithInt:userId] forKey:@"userid"];
[dictionary setObject:SITE_NAME forKey:@"site"];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:urlstring parameters:dictionary constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:imageData name:@"profile_image" fileName:imageName mimeType:@"image/jpg"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
//My Code to parse response
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//failure
[self callTarget:self.request.delegate Selector:self.request.failureSelector WithObject:SOMETHING_WENT_WRONG_MSG];
}];
作为回应,我得到了:
Notice: Undefined index: site in /var/www/vhosts/mysite.de/httpdocs/api/profile_image.php on line 14
{"status":"error","message":"No profile_image provided."}
答案 0 :(得分:0)
试试这个:
NSData *imageData = UIImageJPEGRepresentation(image, 1);
希望这会有所帮助.. :)