2011-06-03 78 views
0

幾天後,我查找了代碼中的錯誤,但沒有成功,現在我真的想知道什麼是錯誤的。
問題是我想從我的Iphone發送一個UIImage到我的服務器,但我收到我的服務器上的一個空白圖像每次...我不知道,但我認爲問題來自我轉換圖像。 UIImage來自方法takePicture。
請檢查我的代碼:發送圖像問題POST

首先我打電話takePicture和:

- (void)imagePickerController:(UIImagePickerController *)aPicker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
self.testImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
} 

testImage是我的ViewController的屬性。
後來我做這個派的UIImage:

NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(testImage)]; 
NSURL *url = [NSURL URLWithString:@"http://myserver/mytest.php"]; 
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; 
[request addData:imageData withFileName:@"tmp.png" andContentType:@"image/png" forKey:@"userfile"]; 
[request setRequestMethod:@"POST"]; 
[request setDelegate:self]; 
[request startAsynchronous]; 

和看到的結果:

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
// Use when fetching text data 
NSString *responseString = [request responseString]; 
NSLog(@"response: %@", responseString); 

// Use when fetching binary data 
NSData *responseData = [request responseData]; 
} 

- (void)requestFailed:(ASIHTTPRequest *)request 
{ 
NSError *error = [request error]; 
    NSLog(@"Request Failed Error: %@", error); 
} 

,然後我收到我的服務器上的一個空白圖像...
請幫我= '(

回答

0

該問題來自高分辨率圖像。我的聯繫太慢了。當我使用WiFi時,代碼正常工作。

0

我想你實際上是發送一個URL編碼的POST正文,而不是一個多部分的POST正文,這是發送數據所需的,所以你只需要在開始之前執行以下操作要求est:

request.postFormat = ASIMultipartFormDataPostFormat; 
+0

我試過這個,但它不工作= /空白圖像再次 – Volgin 2011-06-06 08:00:26

0

伴侶,

看看你的代碼在這裏: 的NSData *爲imageData = [NSData的dataWithData:UIImagePNGRepresentation(testImage)];

你可以通過在你想要的dpi的括號中增加一個數字來改變圖片的質量,例如,如果我想要它在90 dpi的質量,我會寫這樣的:[NSData dataWithData:UIImagePNGRepresentation(testImage,90)]

我現在您的圖片是在.PNG格式注意到,我總是.JPEG工作,它的工作 ,所以我覺得你應該給它一個嘗試...

祝你好運