2011-06-03 79 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工作,它的工作 ,所以我觉得你应该给它一个尝试...

祝你好运