Sending image through JSON | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Sending image through JSON

Is it possible to insert an image into database through JSON??

2nd Jun 2021, 1:21 PM
Satyam
Satyam - avatar
2 Answers
+ 4
Yes but it would be inefficient. The best you could do with JSON is encode all the raw image data using base 64. That would be making use of 6 bits per byte instead of 8. If you have a MongoDb, you could store the image as a document. If you have an SQL database, it is best to store raw image data using the BLOB type. If you want to send the image over HTTP through JSON, base 64 is the best you can do. I generally wouldn't do this, though. I would send the image's data the same way as most file-upload forms work using an enctype of multipart/form-data because that is more efficient and closer matches how HTML forms usually work.
2nd Jun 2021, 4:23 PM
Josh Greig
Josh Greig - avatar
+ 5
Josh Greig is right ☝️
4th Jun 2021, 6:22 AM
Tharul Nejana
Tharul Nejana - avatar