GithubHelp home page GithubHelp logo

fileupload's Introduction

fileupload

This module's main aim is to make file uploads even easier in Node.JS. In it's simplest form, when instantiated, this module returns 4 functions:

  • middleware - route middleware
  • get - to retrieve uploaded files
  • put - to add files to the upload directory
  • delete - to remove uploaded files

Currently only supporting file based uploads, in the near future will support GridFS (mongo db data store), S3 (amazon simple storage services) and SFTP.

Installation

 npm install fileupload

Usage

middleware()

Route middleware for connect to process file uploads.

File uploads have been built in to Connect since 1.8, but they dont come in to the post body (req.body) like other form fields, they get put into req.files.

This piece of route middleware moves the files to the upload directory specified in the constructor and adds the files to req.body as if they were normal form fields.

 var fileupload = require('fileupload').createFileUpload('/uploadDir').middleware;

 app.post('/upload', fileupload, function(req, res) {
   // files are now in the req.body object along with other form fields
   // files also get moved to the uploadDir specified
 });

###get()

Retrieves a file from the upload directory.

 var fileupload = require('fileupload').createFileUpload('/uploadDir');

 fileupload.get('path-to-uploaded-file.gif', function(error, data) {
   // data is the contents of the file
 });

###put()

Puts a file to the upload directory.

 var fileupload = require('fileupload').createFileUpload('/uploadDir');

 fileupload.put('path-to-file.gif', function(error, file) {
   // file is an object with information about the uploaded file
   // See below for the contents of this object
 });

###delete()

Deletes a file from the upload directory.

 var fileupload = require('fileupload').createFileUpload('/uploadDir');

 fileupload.delete('path-to-file.gif', function(error) {

 });

###File object The file objects that are returned from the middleware and put actions contain the following fields:

  • size - size of the file

  • type - mime type of the file

  • path - the folder name that the file has been stored in

  • basename - the name of the file

Here is an example file object:

 {
   size: 3909,
   type: 'image/gif',
   path: 'b36e7d8a26e5dac9be9d9a5ad76cedb5/',
   basename: 'test1.gif'
 }

Todo

  • GridFS
  • S3
  • SFTP
  • Better code documentation

Credits

Dom Harrington

License

Licensed under the New BSD License

fileupload's People

Contributors

bengourley avatar

Watchers

 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.