0

当我请求服务器上传和 UImage 时出现问题

    NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.jpg"]; //UIImage *img = pickerImage;
    [UIImageJPEGRepresentation(postingImage, 0.5) writeToFile:jpgPath atomically:YES];
    NSData *imageData = UIImageJPEGRepresentation(postingImage, 0.5);
    NSURL *url = [NSURL URLWithString:serverURL];
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

    [request setData:imageData withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:@"photo"];

    [request startSynchronous];
    NSLog(@"responseStatusCode %i",[request responseStatusCode]);
    NSLog(@"responseStatusString %@",[request responseString]);

它给出了这个回应

响应状态代码 200

responseStatusString 错误:没有上传文件

有谁知道这件事,我在哪里做错了,

非常感谢您的帮助。

谢谢

4

1 回答 1

0

代替

[request setData:imageData withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:@"photo"];

试试看

[request addData:imageData withFileName:@"image.jpg" andContentType:@"image/jpeg" forKey:@"photo"];

我在 ASIHTTPRequest 的帮助下做了同样的事情,并将图像成功发布在服务器上。我猜这应该可以工作,因为它正在我的一个现场项目中工作。

于 2011-07-16T12:35:40.223 回答