title: Storing images and calling them from MongoDB
body: <p>I have looked around online and gotten only a few methods to work in test code but never on my actual code. I am trying to let the user upload an image in .jpg and then I want to call on it later to be displayed. Here is what I got so far.</p>
  
  <pre><code>fs = require("fs");
  multer= require("multer");
  
  app.use(multer({ dest: "./uploads/:id",
   rename: function (fieldname, filename) {
   return filename;
   },
  }));
  </code></pre>
  
  <p>Then to pull the file from the form I am using:</p>
  
  <pre><code>image: req.body.image
  </code></pre>
  
  <p>As for the code to put it into the DB I am not sure, this is what I came up with but not too sure on if it will work or not. I also am clueless where to put it into my larger route I already have for the rest of the form.</p>
  
  <p>Here is the small code:</p>
  
  <pre><code>app.post("/api/photo",function(req,res){
   var Startup = new Startup();
   Startup.img.data = fs.readFileSync(req.files.userPhoto.path);
   Startup.img.contentType = "image/jpg";
   Startup.save();
  });
  </code></pre>
  
  <p>And here is the working (other than image) route code for the rest of the form.</p>
  
  <pre><code>// CREATE add new startup to database
  app.post("/startup-submit", function(req, res) {
     // Get data from form
    I create the variables here, removed as too much code and code for the image draw is above.    
     //Pass data through | Write better explaination later
     var newStartup = {about_startup: about_startup, social_media: social_media, about_founder: about_founder};
     Startup.create(newStartup, function(err, newlyCreatedStartup){
         if(err){
             console.log(err);
         } else {
             // Redirect back to show all page
             res.redirect("/startups");
         }
     });
  });
  </code></pre>
  
  <p>I know the route paths on the small and large code don't line up but i was using that for testing.</p>
  
  <p>How can I mesh and fix this code so that it will allow me to upload an image/file to my DB? </p>
  
  <p>Then how would I call it to be an  src using EJS. Would it just be ">    This is the best I have came up with. I am sure it is far from right though.</p>