Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store binary data from post to MongoDB

I have small images I want to store as a bin data item. The form is posted but I do not know what to do in the controller so that if I so this, the data is stored. I am using Sails.js and the form is passing data as "image" with the form having a file input type.

var image = new Images;
image.data = ????
image.save();
like image 935
latitudehopper Avatar asked Sep 28 '22 06:09

latitudehopper


1 Answers

If the images are smaller than 16Mb, you can save them directly using MongoDB's bindata type. You can always convert the binary stream to a Base64 string, and store it as a string file, but that will reduce the allowed image size.

If the image is larger than 16Mb, you have no choice but to use GridFS.

like image 82
Pickels Avatar answered Oct 17 '22 15:10

Pickels