0

Hi I am working with android.I want to send an image from server to android and I had done it with sending url from server.How can I send an image from server to android app via json?? is it possible??

2 Answers2

2

It is possible if you can convert your image at your server to a Base64 encoding string. Then you can send the string to your app via JSON.

You can use Apache Common IOUtils:

Base64.encode(FileUtils.readFileToByteArray(imageFile));

On your app you can convert the string to image, example in this link How to convert a Base64 string into a BitMap image to show it in a ImageView?

Hope that helps

Community
  • 1
  • 1
ipohfly
  • 1,959
  • 6
  • 30
  • 57
0

It is possible to send binary data within Json but you have to escape the binary data (UTF-8 encoding and use Base64.) This will increase the data size. Why not just include the path in JSON and fetch/load it?

Stan Smith
  • 896
  • 7
  • 19