user3011821
user3011821

Reputation:

Send image via json in android

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??

Upvotes: 0

Views: 2916

Answers (2)

Stan Smith
Stan Smith

Reputation: 906

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?

Upvotes: 0

ipohfly
ipohfly

Reputation: 2009

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

Upvotes: 2

Related Questions