-1

I'm trying to convert image to string and save it inside MongoDB. I also want to decode it later.

I'm using only Express, MongoDB and ReactJS and I don't want to upload the image file on my server, they'll be user photo.

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Nima Malaeri
  • 37
  • 1
  • 6
  • Maybe you want to encode image to base64, please refer https://stackoverflow.com/a/20285053/8828489. I think it is not best way to store image by base64 in mongodb. You can try other service to store image or store it on your server. – Ha. Huynh Jan 02 '19 at 22:38

1 Answers1

1

Maybe you want to encode image to base64, please refer How to convert image into base64 string using javascript.

Issues

I think it is not a good way to store an image by base64 in MongoDB. I think it will add overhead.

You can try another service to store image or upload it on your server. In MongoDB, we only store image URI/URL, that will reduce overhead.

There are some services allow you uploads image free with APIs:

Ha. Huynh
  • 1,772
  • 11
  • 27
  • Thank you , its first time im trying to do such thing , also i dont like API from any one , bug companies who give such service make everything easier and i believe they are not helping and just make everyone lazy . i want to make in on my own . if base 64 is not good idea do you know how to handle image from front end to express and then store images somewhere on my server ? – Nima Malaeri Jan 03 '19 at 23:09