Simple express file upload middleware that wraps around busboy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
quilty 8ae2f47db8 still working on tests. add prettier 6 years ago
..
uploads Dropping fs-extra as it's no longer needed. Dropping google eslint rules and simply using eslint:recommended. Upgrading packages. Moved manual tests folder into root level and renamed it to example folder. Various lint cleanups. Added a new option for creating parent path directory 6 years ago
README.md Typo in node.js 6 years ago
index.html add dried out version of tempFileHandler as option for saving files 6 years ago
server.js still working on tests. add prettier 6 years ago

README.md

express-fileupload Examples

Basic File Upload

Your node.js code:

const express = require('express');
const fileUpload = require('express-fileupload');
const app = express();

// default options
app.use(fileUpload());

app.post('/upload', function(req, res) {
  if (Object.keys(req.files).length == 0) {
    return res.status(400).send('No files were uploaded.');
  }

  // The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
  let sampleFile = req.files.sampleFile;

  // Use the mv() method to place the file somewhere on your server
  sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) {
    if (err)
      return res.status(500).send(err);

    res.send('File uploaded!');
  });
});

Your HTML file upload form:

<html>
  <body>
    <form ref='uploadForm' 
      id='uploadForm' 
      action='http://localhost:8000/upload' 
      method='post' 
      encType="multipart/form-data">
        <input type="file" name="sampleFile" />
        <input type='submit' value='Upload!' />
    </form>     
  </body>
</html>

Multi-File Upload

express-fileupload supports multiple file uploads at the same time.

Let's say you have three files in your form, each of the inputs with the name my_profile_pic, my_pet, and my_cover_photo:

<input type="file" name="my_profile_pic" />
<input type="file" name="my_pet" />
<input type="file" name="my_cover_photo" />

These uploaded files would be accessible like so:

app.post('/upload', function(req, res) {
  // Uploaded files:
  console.log(req.files.my_profile_pic.name);
  console.log(req.files.my_pet.name);
  console.log(req.files.my_cover_photo.name);
});