2011-07-16 24 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