How to Install Jquery File Upload With Npm
- Get link
- X
- Other Apps
Blueimp file upload for Express js

A simple express module for integrating the jQuery File Upload frontend plugin.
Fullstack Demo | Tutorial on my web log
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 fabricated. Users can additionally:
- choose the destination filesystem, local or deject-based Amazon S3,
- create thumbnail without heavy external dependencies using lwip,
- setup server-side rules past configuration,
- modify the lawmaking against a test harness.
Installation
Setup an Limited project and install the bundle.
$ npm install blueimp-file-upload-expressjs
Beginners tin follow the tutorial for detailed instructions.
Tests
Unit tests can be run with Jasmine using npm test
or this command:
$ jasmine-node specs/
Manual end to finish tests tin can exist washed with this full project. Change the crave()
path of uploadManager.js
to link it this cloned repository.
Configuration
options = { tmpDir: __dirname + '/tmp', // tmp dir to upload files to uploadDir: __dirname + '/public/files', // bodily location of the file uploadUrl: '/files/', // terminate point for delete road maxPostSize: 11000000000, // eleven GB minFileSize: one, maxFileSize: 10000000000, // ten GB acceptFileTypes: /.+/i, inlineFileTypes: /\.(gif|jpe?chiliad|png)/i, imageTypes: /\.(gif|jpe?thousand|png)/i, copyImgAsThumb : truthful, // required imageVersions :{ maxWidth : 200, maxHeight : 200 }, accessControl: { allowOrigin: '*', allowMethods: 'OPTIONS, HEAD, Get, Mail service, 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-two', //brand certain you know the region, else leave this pick 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?yard|png)/i, imageTypes: /\.(gif|jpe?g|png)/i, copyImgAsThumb : true, // required imageVersions :{ maxWidth : 200, maxHeight : 200 }, accessControl: { allowOrigin: '*', allowMethods: 'OPTIONS, HEAD, Become, Mail service, 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 choice out bucketName : 'xxxxxxxxxxxxxxxxx' } } }; // init the uploader var uploader = require('blueimp-file-upload-expressjs')(options); module.exports = function (router) { router.get('/upload', part(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, part (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, role (err,obj) { res.Json({fault:err}); }); }); return router; }
SSL Support
Set the useSSL
choice to truthful
to use the package with an HTTPS server.
var express = require('express') var fs = crave('fs') var https = require('https'); var app = express() // config the uploader var options = { ... useSSL: true ... }; // init the uploader var uploader = crave('blueimp-file-upload-expressjs')(options); app.get('/upload', role(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 past default create a thumbnail
binder and place the specified width/meridian thumbnail in it.
Optionally, y'all tin can omit the maxHeight
. In this case, information technology will exist resize proportionally to the specified width.
imageVersions: { maxWidth: 200 },
as well
imageVersions: { maxWidth: 200, maxHeight : 'automobile' },
PS : auto
value works only with height.
Y'all tin 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, pinnacle : 600 }, "medium" : { width : 300, height : 300 }, "pocket-sized" : { width : 150, height : 150 } }, storage: { type: 'local' } };
Contributions
Changes and improvements are welcome! Feel complimentary to fork and open a pull request.
To Do
- Make Configuration documentation clearer and shorter,
- Refactor lawmaking 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),
- Provide access to other cloud-based services similar Microsoft Azure.
Washed
-
Set up Thumbnail creation when uploading images with a more 'feasible' approach, -
Amazon S3 integration, -
SSL Support.
License
blueimp-file-upload-expressjs is licensed nether the MIT licence.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF Whatever KIND, Express OR IMPLIED, INCLUDING Merely NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS Exist LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN Activeness OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN Connection WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Current Tags
- 0.4.four ... latest (7 years ago)
29 Versions
- 0.ane.0 ... 8 years ago
- 0.1.one ... 8 years ago
- 0.1.2 ... 8 years ago
- 0.ane.three ... 8 years ago
- 0.i.four ... 8 years ago
- 0.one.5 ... eight years ago
- 0.i.6 ... eight years ago
- 0.1.vii ... 8 years ago
- 0.one.8 ... 8 years ago
- 0.1.ix ... 8 years agone
- 0.2.0 ... 8 years ago
- 0.2.ane ... viii years ago
- 0.ii.2 ... eight years agone
- 0.2.3 ... 8 years ago
- 0.2.iv ... 8 years ago
- 0.2.7 ... viii years ago
- 0.2.eight ... 8 years ago
- 0.2.9 ... viii years ago
- 0.2.10 ... 8 years ago
- 0.two.11 ... eight years ago
- 0.2.12 ... 8 years ago
- 0.iii.0 ... 8 years ago
- 0.3.1 ... vii years agone
- 0.3.2 ... 7 years agone
- 0.4.0 ... 7 years ago
- 0.4.i ... 7 years ago
- 0.4.2 ... 7 years ago
- 0.four.3 ... 7 years agone
- 0.4.four ... 7 years agone
Source: https://npmmirror.com/package/blueimp-file-upload-expressjs
- Get link
- X
- Other Apps
Comments
Post a Comment