• Stars
    star
    104
  • Rank 321,831 (Top 7 %)
  • Language
    JavaScript
  • Created about 10 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple express module for integrating jQuery File Upload.

Blueimp file upload for Express js

Build Status ![Gitter](https://badges.gitter.im/Join Chat.svg)

NPM

* * This project is no longer under active maintenance, if anyone is interested to manage this, please reach out to me. * *

A simple express module for integrating the jQuery File Upload frontend plugin.

Fullstack Demo | Tutorial on my blog

v 0.4.0 Released!

Contents

Main features in v0.4.0

  1. Upgrade lwip to v0.0.6

It means that we can upload and proccess GIF images now.

  1. More NodeJs friendly callback API

Using function(err,data) instead of function(data,err)

Notices on upgrading v0.3.x to v0.4.0

In order to make v0.4.0 to work properly, we need to change the uploader instance's callback function correspondingly as mentioned above.

From v0.3.x style,

uploader.get(req, res, function (obj) {
    res.send(JSON.stringify(obj)); 
});

To v0.4.0 style,

uploader.get(req, res, function (err,obj) {
    if(!err){
        res.send(JSON.stringify(obj));
    }
});

Similar rule that applies to the callback functions of uploader.post and uploader.delete.

History

The code was forked from a sample backend code from the plugin's repo. Adaptations were made to show how to use this plugin with the popular Express Node.js framework.

Although this code was initially meant for educational purposes, enhancements were made. Users can additionally:

  • upgrade lwip to version 0.0.6 to support gif images (New at v0.4.0)
  • choose the destination filesystem, local or cloud-based Amazon S3,
  • create thumbnail without heavy external dependencies using lwip,
  • setup server-side rules by configuration,
  • modify the code against a test harness.

Installation

Setup an Express project and install the package.

$ npm install blueimp-file-upload-expressjs

Beginners can follow the tutorial for detailed instructions.

Configuration

options = {
    tmpDir: __dirname + '/tmp', // tmp dir to upload files to
    uploadDir: __dirname + '/public/files', // actual location of the file
    uploadUrl: '/files/', // end point for delete route 
    maxPostSize: 11000000000, // 11 GB
    minFileSize: 1,
    maxFileSize: 10000000000, // 10 GB
    acceptFileTypes: /.+/i,
    inlineFileTypes: /\.(gif|jpe?g|png)/i,
    imageTypes:  /\.(gif|jpe?g|png)/i,
    copyImgAsThumb : true, // required
    imageVersions :{
        maxWidth : 200,
        maxHeight : 200
    },
    accessControl: {
        allowOrigin: '*',
        allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE',
        allowHeaders: 'Content-Type, Content-Range, Content-Disposition'
    },
    storage : {
        type : 'local', // local or aws
        aws : {
            accessKeyId :  'xxxxxxxxxxxxxxxxx', // required if aws
            secretAccessKey : 'xxxxxxxxxxxxxxxxxxxxxxx', // required if aws
            region : 'us-west-2', //make sure you know the region, else leave this option out
            bucketName : 'xxxxxxxxx' // required if aws
        }
    }
};

Usage with options

(refer tutorial)

// config the uploader
var options = {
    tmpDir:  __dirname + '/../public/uploaded/tmp',
    uploadDir: __dirname + '/../public/uploaded/files',
    uploadUrl:  '/uploaded/files/',
    maxPostSize: 11000000000, // 11 GB
    minFileSize:  1,
    maxFileSize:  10000000000, // 10 GB
    acceptFileTypes:  /.+/i,
    // Files not matched by this regular expression force a download dialog,
    // to prevent executing any scripts in the context of the service domain:
    inlineFileTypes:  /\.(gif|jpe?g|png)/i,
    imageTypes:  /\.(gif|jpe?g|png)/i,
    copyImgAsThumb : true, // required
    imageVersions :{
        maxWidth : 200,
        maxHeight : 200
    },
    accessControl: {
        allowOrigin: '*',
        allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE',
        allowHeaders: 'Content-Type, Content-Range, Content-Disposition'
    },
    storage : {
        type : 'aws',
        aws : {
            accessKeyId :  'xxxxxxxxxxxxxxxxx',
            secretAccessKey : 'xxxxxxxxxxxxxxxxx',
            region : 'us-east-1',//make sure you know the region, else leave this option out
            bucketName : 'xxxxxxxxxxxxxxxxx'
        }
    }
};

// init the uploader
var uploader = require('blueimp-file-upload-expressjs')(options);


module.exports = function (router) {
    router.get('/upload', function(req, res) {
      uploader.get(req, res, function (err,obj) {
            if(!err){
                res.send(JSON.stringify(obj));
            }
      });
      
    });

    router.post('/upload', function(req, res) {
      uploader.post(req, res, function (error,obj, redirect) {
          if(!error)
          {
            res.send(JSON.stringify(obj)); 
          }
      });
      
    });
    
    // the path SHOULD match options.uploadUrl
    router.delete('/uploaded/files/:name', function(req, res) {
      uploader.delete(req, res, function (err,obj) {
            res.Json({error:err}); 
      });
      
    });
    return router;
}

SSL Support

Set the useSSL option to true to use the package with an HTTPS server.

var express = require('express')
var fs = require('fs')
var https = require('https');

var app = express()

// config the uploader
var options = {
    ...
    useSSL: true
    ...
};

// init the uploader
var uploader = require('blueimp-file-upload-expressjs')(options);

app.get('/upload', function(req, res) {
    uploader.get(req, res, function (err,obj) {
    if(!err)
        res.send(JSON.stringify(obj)); 
})
    .post('/upload', // ...
    .delete('/uploaded/files/:name', // ...

// create the HTTPS server
var app_key = fs.readFileSync('key.pem');
var app_cert = fs.readFileSync('cert.pem');

https.createServer({key: app_key, cert: app_cert}, app).listen(443);

Multiple thumbnails

To generate multiple thumbnails while uploading

var options = {
  tmpDir: __dirname + '/../public/uploaded/tmp',
  uploadDir: __dirname + '/../public/uploaded/files',
  uploadUrl: '/uploaded/files/',
  copyImgAsThumb: true, // required
  imageVersions: {
    maxWidth: 200,
    maxHeight: 200
  },
  storage: {
    type: 'local'
  }
};

copyImgAsThumb needs to be set to true. imageVersions, maxWidth and maxHeight will by default create a thumbnail folder and place the specified width/height thumbnail in it.

Optionally, you can omit the maxHeight. In this case, it will be resize proportionally to the specified width.

imageVersions: {
    maxWidth: 200
  },

also

imageVersions: {
    maxWidth: 200,
    maxHeight : 'auto'
  },

PS : auto value works only with height.

You can also specify multiple thumbnail generations like

var options = {
  tmpDir: __dirname + '/../public/uploaded/tmp',
  uploadDir: __dirname + '/../public/uploaded/files',
  uploadUrl: '/uploaded/files/',
  copyImgAsThumb: true,
  imageVersions: {
    maxWidth: 200,
    maxHeight: 'auto',
    "large" : {
        width : 600,
        height : 600
    },
    "medium" : {
        width : 300,
        height : 300
    },
    "small" : {
        width : 150,
        height : 150
    }
  },
  storage: {
    type: 'local'
  }
};

Get Form Fields along with Upload

Form fields will come as a part of a JSON object of fileInfo(like title/description). If not specified then will return empty object. [PR42]

Refer to : How to submit additional form data to send additional form data from the client.

Tests

Unit tests can be run with Jasmine using npm test or this command:

$ jasmine-node specs/

Manual end to end tests can be done with this full project. Change the require() path of uploadManager.js to link it this cloned repository.

Contributions

Changes and improvements are welcome! Feel free to fork and open a pull request.

To Do

  • Make Configuration documentation clearer and shorter,
  • Refactor code to build tests and provide generic transports as in winston,
  • Write end to end tests with WebdriverIO,
  • Provide a basic image processing pipeline (resizing, croping, filter effects),
  • Fix AWS thubnail issue,
  • Provide access to other cloud-based services like Microsoft Azure.

Done

  • Fix Thumbnail creation when uploading images with a more 'feasible' approach,
  • Amazon S3 integration,
  • SSL Support.

License

blueimp-file-upload-expressjs is licensed under the MIT licence.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

diskDB

A Lightweight Disk based JSON Database with a MongoDB like API for Node
JavaScript
598
star
2

myRESTApp

Architecting a Secure RESTful Node.js app
CSS
139
star
3

cli-adventure-games

Text Based Adventure Games built with Node.js
JavaScript
111
star
4

mydashboard

node webkit based dashboard app
JavaScript
97
star
5

pi_livestreaming

Raspberry Pi, Camera and Node.js – Live Streaming with Websockets #IoT
JavaScript
91
star
6

BucketListApp

BucketListApp
JavaScript
52
star
7

jsTree-directive

An Angular Directive for jsTree. Docs :
JavaScript
51
star
8

vTak

A Desktop based Chat app with node-webkit, Firebase and Angularjs
JavaScript
47
star
9

expressjs-fileupload

A simple express module for integrating jQuery File Upload.
JavaScript
46
star
10

fileBrowserApp

Building a Web Based File Browser with jsTree, Angularjs and Expressjs
CSS
45
star
11

slush-wean

A slush generator to generate Webkit Express Angular Node desktop apps
JavaScript
35
star
12

ng2do-mean-app

Developing a MEAN app with Angular 2.0
JavaScript
34
star
13

todoApp

Re-Architecting a Firebase app to work with Node.js and MongoDB
JavaScript
32
star
14

slush-meanjs

A slush generator to scaffold MEAN Apps
JavaScript
31
star
15

nwk-videochat

Node-Webkit, WebRTC and Angularjs – A Video Chat Client
JavaScript
30
star
16

MEAN-Todo-App

A Todo MEAN App - MongoDB, Expressjs, Angularjs and Nodejs
JavaScript
29
star
17

generator-framework7-phonegap

A yeoman Generator for scaffolding Framework7/PhoneGap App
CSS
28
star
18

ngTwitterApp

Angularjs, Material Design and Twitter Streams – A Twitter Live Search App
JavaScript
26
star
19

myTwilioApp

Twilio, Ionic Framework and Node.js – A Message & Call App
JavaScript
24
star
20

wordpress-offline-viewer

Electron, WordPress & Angular Material – An Offline Viewer
JavaScript
24
star
21

remindme

A Twilio Reminder App
JavaScript
20
star
22

mediaPlayerApp

Ionic Framework, Cordova and File API – A Media Player App
JavaScript
19
star
23

chatter

Node Webkit, Firebase and Ionic Framework – A one to one chat client
JavaScript
19
star
24

dropzone-express-fileupload

Fileupload with Dropzone & Express.js
JavaScript
17
star
25

slush-mongo

A slush generator for MongoDB
JavaScript
16
star
26

ngMovieStub

Online Movie tickets booking via Angularjs - A Hands on tutorial.
JavaScript
16
star
27

generator-onsenui-phonegap

A yeoman Generator for scaffolding Onsen UI/PhoneGap App
JavaScript
14
star
28

MEAN-Workshop

A repo for the 5 Day "App development with MEAN Stack" Workshop
CSS
14
star
29

lazyboy

Command line laziness redefined! This module is language agonistic. It can store any command line statement as shortcuts!
JavaScript
12
star
30

restify-mongojs-app

JavaScript
12
star
31

listMyAPI

List out all the routes that are configured in an Express js app or a Restify app
JavaScript
12
star
32

LovedOneNotifier

Loved One Notifier
JavaScript
11
star
33

spaceinvaders-game

Mary live-codes a JavaScript game from scratch – Mary Rose Cook at Front-Trends 2014
JavaScript
10
star
34

myIonicFireApp

A Ionic Framework + Firebase BucketList app - Code
JavaScript
10
star
35

slush-express

A slush generator to scaffold Express apps
JavaScript
10
star
36

ionCordova

Getting Started with ngCordova
JavaScript
9
star
37

nwkFilePlayer

Node-Webkit File Player – A File player for your desktop
JavaScript
8
star
38

mqttApp

Getting started with Message Queue Telemetry Transport (MQTT)
JavaScript
8
star
39

smartMouth

Your Friend in Foreign Lands!
Java
8
star
40

fill-image

An Angular Directive for placeholder images. Docs & Demo:
JavaScript
8
star
41

nwk-fb-auth

node-webkit and Firebase - Simple and Social Authentication
JavaScript
8
star
42

movieFire

Example demonstrating Firebase Integration with Pure Javascript and Angularjs
JavaScript
8
star
43

slush-ng

A minimalist Angularjs boiler plate
JavaScript
7
star
44

DEAN-Todo-App

A Todo DEAN App - DiskDB, Expressjs, Angularjs and Nodejs
CSS
7
star
45

howBrowserWorks

A Presentation on how browser works (compiled from various sources)
7
star
46

arvindr21.github.io

Github Home Page
Stylus
6
star
47

myNodeWebKitApps

Build Native Apps using Node Webkit
JavaScript
6
star
48

Pi_MorseCode

Raspberry Pi, Node.js and a LED – Emit Morse Code
JavaScript
6
star
49

pushbots-cordova

Pushbots and Cordova - Easy Push Notifications for your app
Java
6
star
50

slush-electron

Boilerplate application for Electron runtime inspired by szwacz/electron-boilerplate
JavaScript
6
star
51

lwip-examples

Image Manipulation with Node.js and L.W.I.P.
JavaScript
6
star
52

pi_printToLCD

Raspberry Pi, 16x2 LCD and Node.js - Print stuff
JavaScript
5
star
53

pi_DoorBell

Raspberry pi, a Buzzer and Node.js – An IoT Doorbell
JavaScript
5
star
54

mongoDBPagination

A simple Expressjs/Mongojs app that shows how to implement Pagination using MongoDB Skip and Limit
CSS
5
star
55

pi_videoEMailIntruder

Raspberry Pi, Camera, Node.js – Video The Intruder
JavaScript
5
star
56

nwk-ngApp

An Angular node-webkit application
JavaScript
5
star
57

ng2

Getting Started with Angular 2.0
JavaScript
4
star
58

react-redux-apollo-graphl-mongodb-boilerplate

React Redux Apollo GraphQL Mongo Passport boilerplate
JavaScript
4
star
59

ngcordova-phonegap-build

Getting Started with ngCordova - A repo to submit the app to Phonegap Build service
JavaScript
4
star
60

slush-webstarterkit

One command scaffold-er for Google's Web Starter Kit. No questions asked!
CSS
4
star
61

my-shopify-sales-channel-app

JavaScript
4
star
62

sentimentAnalysisApp

A Nodejs based sentiment analysis app
JavaScript
4
star
63

pi_intruderAlert

Raspberry pi, PIR Sensor and Node.js – An IoT Intruder Alert system
JavaScript
4
star
64

html-css-js-jquery-bootstrap-angular

Practice material for html-css-js-jquery-bootstrap-angular
JavaScript
4
star
65

tddBootstrapBoilerPlate

A LESS driven Bootstrap boilerplate integrated with Grunt, Bower, Jasmine, Istanbul & Karma
CSS
3
star
66

json-server-pack

json-server-pack
JavaScript
3
star
67

RottenTomatoesjQueryRestClient

jQuery plugin/wrapper for Rotten Tomatoes REST API
JavaScript
3
star
68

slush-bootstrap

A Slush generator for Bootstrap SASS/LESS/CSS projects
HTML
3
star
69

helloPhoneGap

JavaScript
3
star
70

js-iot

A presentation on Javascript & Internet of Things
CSS
3
star
71

slush-angularfire

A slush generator to scaffold an Angular-Firebase App
JavaScript
3
star
72

myBlogsHybridApp

Web Components based Hybrid App for my Wordpress Blog
Java
3
star
73

myWebComponents

Web Components – The Future Web
JavaScript
3
star
74

slush-h5bp

A HTML5 Boilerplate generator for Slush
CSS
2
star
75

slush-nwk-xprs

A slush generator to generate node-webkit express apps
JavaScript
2
star
76

practice-session

practice-session
2
star
77

dnaAnalysis

DNA Analysis with Node.js
JavaScript
2
star
78

theJackalofJavascriptApp

A Hybrid app for my Blog
CSS
2
star
79

slush-reveal

A Slush Generator for creating Revealjs presentation.
JavaScript
2
star
80

disk-db-async

A Lightweight Disk based JSON Database with a MongoDB like API for Node. Rewriting [arvindr21/diskDB](https://github.com/arvindr21/diskDB) to follow TypeScript and latest convention.
TypeScript
2
star
81

PhoneGap3ContactsAPI

A Tutorial Repo for PhoneGap 3 Contacts API.
Java
2
star
82

BucketList-PhoneGapBuild

JavaScript
2
star
83

docker-node-app

Developing Nodejs applications in Docker
JavaScript
2
star
84

Em_HandsOn

Emberjs - A hands on Tutorial
JavaScript
2
star
85

ng-mat-fire

ng-mat-fire
TypeScript
1
star
86

pi_checkRain

Raspberry Pi, Node.js and Twilio – Is It Raining Arvind? #IoT
JavaScript
1
star
87

myOnsenUIApp

myOnsenUIApp
JavaScript
1
star
88

lower-case

An inline element to make content inside it lower-case
CSS
1
star
89

upper-case

An inline element to make content inside it upper-case
CSS
1
star
90

clientSideStorage

Getting Started with Client Side Storage
HTML
1
star
91

myFirefoxOSApp

A GeoNames Weather app
JavaScript
1
star
92

eventsFeed-Meteorjs

eventsFeed-Meteorjs
JavaScript
1
star
93

color2code

Get color code from color name
JavaScript
1
star
94

etl-app

etl-app
JavaScript
1
star
95

phoneGapFramework7Boilerplate

phoneGap Framework7 Boilerplate
JavaScript
1
star
96

live-server-pack

live-server-pack
JavaScript
1
star
97

generator-wchybridapp

Web Compoenets based Hybrid App generator for your Wordpress Blog
CSS
1
star
98

rwdTestAutomationBoilerplate

This is a sample framework on how to test Responsiveness of a RWD page
CSS
1
star
99

npm-calculator

A node package manager example to setup a calculator
JavaScript
1
star
100

amzcrawler

amzcrawler
JavaScript
1
star