2012-09-04 63 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'))> 
相關問題