Coder Social home page Coder Social logo

express-file-store's Introduction

express-file-store

express middleware to access/write/remove files (using file path) with various backends.

NPM Package Build Status Dependencies

Usage (middleware)

$ npm install express-file-store --save
var express = require('express');
var FileStore = require('express-file-store');

// using file system
var fileStore = FileStore('fs', {
  path: __dirname + '/public/uploads'
});

// or using gridfs
var fileStore = FileStore('gridfs', {
  url: 'mongodb://localhost:27017/test'
});

// or using s3
var fileStore = FileStore('s3', {
  key: process.env.AMAZON_ACCESS_KEY_ID,
  secret: process.env.AMAZON_ACCESS_KEY_SECRET,
  bucket: 'test',
  region: 'ap-southeast-1'
});

// in express
var app = express();

// POST /a/b/c.png to upload
// GET /a/b/c.png to download
// DELETE /a/b/c.png to remove
app.use(filestore.routes);

// or directly

fileStore.get('/a/b/c.png', function(err, file) {
  console.log(err, file); // null, { filename: '/a/b/c.png', contentType: 'image/png', length: 512, stream: [Readable] }
});

fileStore.put({
  filename: '/a/b/c/d.pdf',
  contentType: 'application/pdf',
  stream: fs.createReadStream('/d.pdf')
}, function(err) {
  console.log(err); // undefined
});

fileStore.remove('../../../../../usr', function(err, file) {
  console.log(err.message); // 'File not found'
});

// ...

Usage (standalone)

$ npm install -g express-file-store
$ efs gridfs -p 8080 -u mongodb://localhost:27017/test # start a server with gridfs backend
$ efs fs -p 8080 -p $(pwd) # start a server with fs backend
$ efs fs # will start file server on port 8080 in current pwd
$ efs s3 -p 8080 -k $AMAZON_ACCESS_KEY_ID -s $AMAZON_ACCESS_KEY_SECRET -b $S3_BUCKET -r $S3_REGION # start a server with S3 backend
$ curl -F [email protected] http://localhost:8080/README.md
$ curl --data-binary @package.json -H "Content-Type: application/json" http://localhost:8080/package.json

Development

$ git clone [email protected]:seedalpha/express-file-store.git
$ cd express-file-store
$ npm install
$ npm test # make sure you have mongodb and s3 credentials in place

Author

Vladimir Popov [email protected]

License

MIT

express-file-store's People

Contributors

rusintez 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.