ASIFormDataRequest返回错误

时间:2011-07-16 12:23:31

标签: iphone upload asihttprequest asiformdatarequest

当我向服务器请求上传和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]);

它正在给出这个回复

  

responseStatusCode 200

     

responseStatusString错误:没有上传文件

任何人都知道这一点,我在做错了,

非常感谢您的帮助。

谢谢

1 个答案:

答案 0 :(得分:0)

而不是

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

尝试

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

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