How to store image as encoded string in MongoDB?












-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.










share|improve this question

























  • Maybe you want to encode image to base64, please refer 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.

    – huynhsamha
    Jan 2 at 22:38


















-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.










share|improve this question

























  • Maybe you want to encode image to base64, please refer 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.

    – huynhsamha
    Jan 2 at 22:38
















-1












-1








-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.










share|improve this question
















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.







javascript reactjs mongodb express






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 22:37









Emile Bergeron

10.7k44672




10.7k44672










asked Jan 2 at 22:27









Nima MalaeriNima Malaeri

111




111













  • Maybe you want to encode image to base64, please refer 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.

    – huynhsamha
    Jan 2 at 22:38





















  • Maybe you want to encode image to base64, please refer 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.

    – huynhsamha
    Jan 2 at 22:38



















Maybe you want to encode image to base64, please refer 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.

– huynhsamha
Jan 2 at 22:38







Maybe you want to encode image to base64, please refer 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.

– huynhsamha
Jan 2 at 22:38














1 Answer
1






active

oldest

votes


















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:





  • Imgur: You can refer Build an Image Uploader with Imgur API and JavaScript


  • Firebase: You can refer Upload Files to Firebase Storage with JavaScript

  • Cloudinary

  • Upload.im

  • Flickr






share|improve this answer
























  • 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 3 at 23:09












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013987%2fhow-to-store-image-as-encoded-string-in-mongodb%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









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:





  • Imgur: You can refer Build an Image Uploader with Imgur API and JavaScript


  • Firebase: You can refer Upload Files to Firebase Storage with JavaScript

  • Cloudinary

  • Upload.im

  • Flickr






share|improve this answer
























  • 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 3 at 23:09
















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:





  • Imgur: You can refer Build an Image Uploader with Imgur API and JavaScript


  • Firebase: You can refer Upload Files to Firebase Storage with JavaScript

  • Cloudinary

  • Upload.im

  • Flickr






share|improve this answer
























  • 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 3 at 23:09














1












1








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:





  • Imgur: You can refer Build an Image Uploader with Imgur API and JavaScript


  • Firebase: You can refer Upload Files to Firebase Storage with JavaScript

  • Cloudinary

  • Upload.im

  • Flickr






share|improve this answer













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:





  • Imgur: You can refer Build an Image Uploader with Imgur API and JavaScript


  • Firebase: You can refer Upload Files to Firebase Storage with JavaScript

  • Cloudinary

  • Upload.im

  • Flickr







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 22:50









huynhsamhahuynhsamha

843418




843418













  • 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 3 at 23:09



















  • 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 3 at 23:09

















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 3 at 23:09





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 3 at 23:09




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013987%2fhow-to-store-image-as-encoded-string-in-mongodb%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory