0.1.6 • Published 10 years ago

danzi v0.1.6

Weekly downloads
7
License
MIT
Repository
github
Last release
10 years ago

DanZi

A uploader middleware for express application. DanZi (担子 dàn zǐ in Chinese) means a burden, which is usually used in oral language.

Installation

$ npm install danzi

Options

  • path A writeable path to store the uploaded file
  • storage A hash contains the cloud service info

Usage

It must be used with express, and be put after bodyParser, see example below.

Example

Write a simple app.js in your express project

var express = require('express');
var danzi = require('danzi');

var app = express();
app
  .use(express.bodyParser())
  .use(danzi({path: __dirname + '/public/upload'}));

app.post('/upload', function(req, res) {
  var versions = {
    thumb: [ 50, 50 ], // [ width, height ] in pixel
    profile: [ 80, 160 ],
    hero: [ 100, 225 ]
  };

  Object.keys(req.files).forEach(function(key) {
    var file = req.files[key];
    // set versions for resizing
    file.versions = versions;
  });

  res.send('Your file is placed at: ' + req.files.file.uri);
});

app.listen(3000);
console.log('listening on port 3000');

Then do a test

node app.js

curl -X POST --form "file=@/path/to/file" "http://localhost:3000/upload"

You will find your files are put into directory public/upload

License

MIT

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago