2012-09-04 54 views
-1

我已经在iphone中做了应用程序,它消耗了coldfusion webservice.我想在远程服务器上的iphone应用程序上显示图像。使用coldfusion webservice我可以从远程server.so检索图像,我想通过webservice将该图像发送到iphone应用程序。那么,这可能吗?请帮me.Thanks提前可以通过Web服务发送图像吗?

+0

是的,你可以参考:通过网络发送图像] [1] [1]:http://stackoverflow.com/questions/5216988 /发送-iphone-camera-captured-images-to-the-web-service-and-getting-respons –

+0

我已经提到,但我想从webservice发送图像到iphone –

回答

1

使用CFFILE或cfimage的读取文件。 Base64对数据进行编码,然后通过web服务发送。在iPhone应用程序的base64解码中,您将拥有图像的二进制文件。

+0

我试过这个代码,但它不给任何输出 #myFile#

+0

这应该工作得很好。 – Paul

-1

你可以通过创建形式上传图像尝试下面的代码

-(void)UploadImage{ 

NSString *urlString = @"yourUrl"; 
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
[request setURL:[NSURL URLWithString:urlString]]; 
[request setHTTPMethod:@"POST"]; 

NSMutableData *body = [NSMutableData data]; 


NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; 
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; 
[request addValue:contentType forHTTPHeaderField:@"Content-Type"]; 

// file 
NSData *imageData = UIImageJPEGRepresentation([self scaleAndRotateImage:[selectedImageObj]],90); 


[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
// [body appendData:[[NSString stringWithString:@"Content-Disposition: attachment; name=\"user_photo\"; filename=\"photoes.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 

[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\"%@.jpg\"\r\n",@"ImageNmae"] dataUsingEncoding:NSUTF8StringEncoding]]; 

[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
[body appendData:[NSData dataWithData:imageData]]; 
[body appendData:[[NSString stringWithString:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 


// close form 
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
// set request body 
[request setHTTPBody:body]; 
//return and test 
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; 

    } 
+0

我不想上传图像。我只是想显示放在远程服务器上的图像,这是通过web服务检索.SO coldfusion webservice包含图像和图像我想发送的iPhone应用程序将要显示 –

1

保罗是在正确的轨道上。但是,您很可能需要以不同的方式读取源文件。从我发现的过去,你需要获得文件和base64的二进制文件。所以,这个代码应该为你工作..

<cfset myFile = toBase64(fileReadBinary('path.to.image.file'))> 
相关问题