Convert Image to JSON

With my Android app, I want to upload text and image to the server. My problem is how to convert the image (from my phone) to a json or json array object. (I am using 1.6 android sdk for my application)

+4
source share
2 answers

Usually you encode binary data as Base64 . This allows you to represent any type of byte data as text. Consider the fact that the image expands to a 4: 3 ratio.

Edit: How to convert an image to a Base64 string? (here you will find Base64 helper for API less than 8)

+2
source

You must first be sure that you want to do this. Perhaps there is a way to save the image as a regular file (or attachment?) On your server.

Otherwise, get byte data from the image. Then convert the byte after the byte into a huge string. Then the string can be saved as a property in your JSON object. You can use Base64 encoding.

+2
source

Source: https://habr.com/ru/post/1383666/


All Articles