A uploader middleware for express application
A uploader middleware for express application. DanZi (担子 dàn zǐ in Chinese) means a burden, which is usually used in oral language.
$ npm install danzi
pathA writeable path to store the uploaded file
storageA hash contains the cloud service info
It must be used with express, and be put after bodyParser, see example below.
Write a simple app.js in your express project
var express = require'express';var danzi = require'danzi';var app = express;appuseexpressbodyParserusedanzipath: __dirname + '/public/upload';apppost'/upload'var versions =thumb: 50 50 // [ width, height ] in pixelprofile: 80 160hero: 100 225;ObjectkeysreqfilesforEachvar file = reqfileskey;// set versions for resizingfileversions = versions;;ressend'Your file is placed at: ' + reqfilesfileuri;;applisten3000;console.log'listening on port 3000';
Then do a test
node app.jscurl -X POST --form "file=@/path/to/file" ""
You will find your files are put into directory