Giter Club home page Giter Club logo

nodejs-multiple-file-upload-example's Introduction

multipleFileUploadWithExpressJS

Description: how to upload multiple files and save them with express.js version 4.x ( node.JS library )

___ important key factors ___##

####1. preparing the html to handle file upload properly.####

  <form action="/uploadFiles" method="post" enctype="multipart/form-data">
    <input type="file" multiple="multiple" accept="image/*" name="uploadedImages"/><br/>
    <input type="submit" value="Upload" />
  </form>

multiple attribute allow multiple files to be selected from the file browser. Supported in IE10, Firefox, Opera, Chrome, and Safari.
accept attribute tells the browser what type of files to allow to select by default.
name attribute with a given value is required for nodeJS to be able to get referenced. enctype="multipart/form-data" The enctype attribute specifies how the form-data should be encoded when submitting it to the server. The enctype attribute can be used only if method="post"

####2. getting ready for reading the uploaded files####

    app.use(express.bodyParser()); // required for accessing req.files object

####3. handling the uploaded files #1####

    req.files.uploadedImages.forEach(function (element, index, array) {
      fs.readFile(element.path, function (err, data) {
        var newPath = __dirname + "/public/uploadsDirectoryname/" + element.name;
        fs.writeFile(newPath, data, function (err) {
          if(err) {
            console.log(err);
          }
        });
      });

####TODO####

  • upload files with ajax automatically when they are selected.
  • when multiple files are selected, show them immediately, add progress indicator as well.
  • add support for older shitty browsers, that doesn't support html5 multiple file upload
  • consider uploadify.com/demos/ as a possible fallback.

nodejs-multiple-file-upload-example's People

Contributors

burib avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.