【发布时间】:2010-03-11 16:30:17
【问题描述】:
我正在尝试上传我在相机的帮助下单击的图像。我正在尝试使用以下代码将图像上传到远程服务器。
-(void)searchAction:(UIImage*)theImage
{
UIDevice *dev = [UIDevice currentDevice];
NSString *uniqueId = dev.uniqueIdentifier;
NSData * imageData = UIImagePNGRepresentation(theImage);
NSString *postLength = [NSString stringWithFormat:@"%d",[imageData length]];
NSString *urlString = [@"http://www.amolconsultants.com/im.jsp?" stringByAppendingString:@"imagedata=iPhoneV0&mcid="];
urlString = [urlString stringByAppendingString:uniqueId];
urlString = [urlString stringByAppendingString:@"&lang=en_US.UTF-8"];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:imageData];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn == nil)
{
NSLog(@"Failed to create the connection");
}
}
但是什么都没有发布。控制台窗口中也没有任何内容。我在操作表中调用此方法。当用户单击操作表的第一个按钮时,会调用此方法来发布图像。
谁能帮帮我...
任何代码都会很有帮助...
提前谢谢...
【问题讨论】:
-
我没有立即看到您的代码有任何问题,无论如何您应该在控制台窗口中看到输出。您是否尝试过使用调试器单步执行?
-
不,我没有尝试调试程序...
标签: iphone objective-c remote-server image-upload