I want to add an image file into json object . Is it possible to add image file into json object?
I tried below code but its not working ? Because i want to send that json object to the server then server will read my image file and store into that database.
JSONObject test = new JSONObject(); test.put("photo",new File(// Here i set image uri));
So when I print this json object it only show me the image path where the image stored. I want file for sending it to server.
Steps for Appending to a JSON File In Python, appending JSON to a file consists of the following steps: Read the JSON in Python dict or list object. Append the JSON to dict (or list ) object by modifying it. Write the updated dict (or list ) object into the original file.
To show the text values (such as the name and id) I can use the elements innerHTML property. However, to display the images using the URLs, I have to first create an <img> element (for each record in the JSON file), and assigning the URL as source to the <img> elements, which is then added to a <table> cell.
You will need to read the bytes
from that File
into a byte[]
and put that object into your JSONObject
.
You should also have a look at the following posts :
Hope this helps.
You're only adding the File object to the JSON object. The File object only contains meta information about the file: Path, name and so on.
You must load the image and read the bytes from it. Then put these bytes into the JSON object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With