[英]Undefined index for uploading image on server iOS
我正在尝试在服务器上上传图像,但收到服务器的意外响应。
这是我正在使用的代码:
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."}
尝试这个:
NSData *imageData = UIImageJPEGRepresentation(image, 1);
希望这可以帮助.. :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.