How to Store and Retrieve image in MongoDb using sailsjs?

How to define the model for storing image for the following

var Person = {
  attributes: {
     firstName: 'STRING',
     lastName: 'STRING',
     age: 'INTEGER',
     image: 'STRING'
    }
};

module.exports = Person;

What should be the 'image' type and how to store image?

How to store and update image using model 'Person'?

Answers


You could convert the image to a base64-encoded data-URL and store it in a 'STRING' field. But keep in mind that MongoDB documents have a size restriction of 16MB. When you want to store larger images, you should consider to store them using GridFS. In that case your Person.image field would be a 'STRING' with the GridFS filename while the image data itself is stored on GridFS.


Need Your Help

Detect red color in different illumination or background

opencv colors computer-vision

I can't find the best way to detect red color in different illumination or background.