2011-07-16 51 views
0

我得到一个问题,当我请求到服务器的上传和的uImageASIFormDataRequest返回错误

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 Error: No file uploaded

是否有任何人知道这件事,我在哪里做错了,

你的帮助是非常感谢。

谢谢

回答

0

相反

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

尝试为

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

我也同样用ASIHTTPRequest的帮助,并获得成功发布在服务器上的图像。这应该工作,因为它在我的一个活动项目中工作。

+0

谢谢Jennis!我曾尝试使用addData:但它仍然显示“错误:没有文件上传”,它可能是我的服务器的问题!? – Ganesh