Admin
Admin

Reputation: 193

send image to android app using restful wcf

I have a restful wcf service. I have to send images from service to android app. I can not use or provide direct url of images to download for security reasons. Images are less than 2MB in size. I am using ByteArray to send image from WCF service to Android app in json, as :

<OperationContract()> _
<WebGet(UriTemplate:="/GetFile", ResponseFormat:=WebMessageFormat.Json, RequestFormat:=WebMessageFormat.Json)> _
Function GetFile(Byval Token as String) As Byte()

GetFile function returns an image as ByteArray. I am confused as i have gone through many websites.

Is the byte array converted to Base64String. If yes then the image received by android client will be about 30% more in size.

My question is

What is the best way to send image (less than 2MB) from restful wcf to android app without increasing its data size. (without any Base64 or any conversion)?

Sending image as Stream rather than ByteArray creates an overhead to the server and high memory use?

Upvotes: 1

Views: 269

Answers (1)

Mohammad
Mohammad

Reputation: 2764

ByteArray is not good practice. serializing ByteArray is too slow. in order to solve this problem suggested to convert ByteArray to Base64String. but if you don't want to increase the size you can stream the image. sending stream has no overhead but you cant serialize anything else with your stream. which its OK in your case.

Upvotes: 1

Related Questions