0

I'm running into an issue where I can't get the base64 encoded string to copy and paste into my terminal, so I can't store the base64 encoded image...

Background- Hey, I'm doing a project that uses MERN stack (MongoDB, Express, React, and Node.js). I'm using the database to store images--the images themselves are too long, so I used base64 encoding to compress them. They're too long to copy/paste. I'm super new too all of this, Mongo, Express, React, and Node.js. I guess I'm just looking for the best way to either shorten the string or compress the image more before base64 encoding it. Thanks!

Edit I will be uploading ~125 images. They're likely going to be around 14k KB each.

Annie
  • 1
  • 3
  • 2
    Seems you should read about [GridFS](https://docs.mongodb.com/manual/core/gridfs/) in the documentation. Note you should only need that when the data to be stored exceeds 16MB. At any rate there is no need to "encode to Base64" here. Base64 encoding is actually **larger** than the regular binary size so you are not "compressing" by doing this. Also even though MongoDB *represents* binary data as Base64 encoded when viewed from the shell, it's actually still "binary" in real storage. In all cases just read the bytes and store them with code. No "copy/paste" required. – Neil Lunn Nov 13 '18 at 21:36
  • So don't use GridFS for 14K files, but don't encode to Base64 either. Plenty of linked examples there showing you how to simply read binary content and put it directly into a MongoDB document property. – Neil Lunn Nov 13 '18 at 22:40

1 Answers1

0

You should not keep base64 image in the database. You have to keep it in the file system as usual image and store it’s path in the database.