Storing image in MongoDB Database

1,396

Solution 1

I would suggest encoding your images to Base64 format. Then you can store them technically as plain text. There is a base64Encode function in dart:convert package.

You can also check this discussion: how to convert an image to base64 image in flutter?

Solution 2

MongoDB has GridFS for storing files:

A convention for storing large files in a MongoDB database. All of the official MongoDB drivers support this convention, as does the mongofiles program.

It looks like mongo-dart supports it as well although it's missing the documentation.

Share:
1,396
yash_412
Author by

yash_412

Updated on December 21, 2022

Comments

  • yash_412
    yash_412 over 1 year

    How can I store images in a MongoDB through Flutter/Dart?

    We are developing an android application using MongoDB and Flutter. We want to store images during the registration of users in our app. I already referred the mongo-dart documentation but still, I can't find any solution about this.

    • Alexpandiyan Chokkan
      Alexpandiyan Chokkan almost 4 years
      IMO, Convert & store as base64 would be better option.
    • yash_412
      yash_412 over 3 years
      Ya It works. Thanks for your comment
  • Femn Dharamshi
    Femn Dharamshi over 1 year
    Is there any blog, or documentation now available for gridfs in mongo-dart?