我有我的iPhone应用程序连接到WCF服务。现在我需要添加一个上传照片功能,我的iPhone应用程序。这就是说,我需要让我的WCF服务接受图像并保存到我的服务器。任何想法如何实现这一目标?
I have a WCF service that my iPhone app is connected to. Now I need to add an upload photo feature to my iPhone app. That said, I needed to have my WCF service to accept Images and save it to my server. Any idea how to achieve this?
我没有使用Google的一些可能的解决方案,但他们都没有为我工作。
I did googling for some possible solutions but neither of them works for me.
您回应大大AP preciated。
Your responses is greatly appreciated.
样品code段,没有错误张贴图像检查只是基本的code
sample code snippet, no error checking just basic code for posting image
// get image from somewhere...
NSData *imageData = UIImageJPEGRepresentation(image, 90);
NSString *urlString = @"http://yourserver.com/upload_image";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSMutableData *postBody = [NSMutableData data];
//add image data to POST
[postBody appendData:[NSData dataWithData:imageData]];
[request setHTTPBody: postBody];
// connect to the web
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *respStr = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding];