title: Angular 6 file uploading
body: <p>Been stuck on this for a while now.  I have a mean stack application using angular 6.  I'm trying to upload save a file to my backend.  I've found <a href="https://stackoverflow.com/questions/47936183/angular-5-file-upload">THIS</a> article.  But either I receive an error a crypt something like</p>
  
  <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; 
  &lt;title&gt;Error&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;pre&gt;Error: ENOENT: no such file or 
   directory, open ''&lt;br&gt; at 
   Error (native)&lt;/pre&gt; &lt;/body&gt; &lt;/html&gt;
  </code></pre>
  
  <p>returned from the server or the req.file is empty and my save doesnt happen.  I'm trying to piece together the best way to do this.  </p>
  
  <p>Thanks</p>
  
  <p>here is my end point</p>
  
  <pre><code>app.post('/api/posts', upload.single('file'), (req, res, next) =&gt; {
  
  const post = new Post({
    title: req.body.title,
    content: req.body.content,
    image:req.file
  });    
  
  post
  .save()
  .then(createdPost =&gt; {
    res.status(201).json({
      status: true,
      id: createdPost._id,
    });
  })
  .catch(error =&gt; {
    res.status(500).json({ status: false, message: 'Didnt save ', error });
  });
  </code></pre>
  
  <p>});</p>
  
  <p>And here is how I set up multer, grid file stream and storage</p>
  
  <pre><code>    let gfs;
  conn.once('open', () =&gt; {
    gfs = Grid(conn.db, mongoose.mongo);
    gfs.collection('uploads');
  });
  
  
  const storage = new GridFsStorage({
    url: connection,
    file: (req, file) =&gt; {
      return new Promise((resolve, reject) =&gt; {
        crypto.randomBytes(16, (err, buf) =&gt; {
          if (err) {
            return reject(err);
          }
          const filename = buf.toString('hex') + path.extname(file.originalname);
          const fileInfo = {
            filename: filename,
            bucketName: 'uploads'
          };
          resolve(fileInfo);
        });
      });
    }
  });
  const upload = multer({ storage });
  </code></pre>