GithubHelp home page GithubHelp logo

ngty / multipart-mongo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oreh/multipart-mongo

1.0 2.0 0.0 97 KB

A connect middleware that handles multipart uploading and stores uploaded files into mongodb

License: MIT License

JavaScript 100.00%

multipart-mongo's Introduction

Multipart-Mongo

Mutliple-mongo is an extension of the Multipart middleware from Connect. The goal of multipart-mongo is to make it easy for developers to store uploaded files direclty into mongodb (i.e. GridFS).

Ensure that mongodb is installed and running locally. Then start a server as follows

var inspect = require('util').inspect;
var mongo = require('mongoskin');
var db = global.db = mongo.db('localhost/filestore?auto_reconnect=true&poolSize=1');

var connect = require("connect")
  , multipart = require("multipart-mongo")

db.open(function(err, db){
    var app = connect();
    app.use(connect.json());
    app.use(connect.urlencoded());
    app.use(multipart());
    app.use(function(req, res){
        console.log(req.headers);
        if (req.method == 'GET'){
            res.end('Try POST a file\n');
            return;
        }
        if (req.method == 'POST'){
            res.end(inspect(req.files)+'\n');
            return;
        }
        res.end('Not implemented');
    });
    app.listen(3000);
    console.log('Server is running at port 3000. POST to "/" to upload file');
})

From the console, one can upload a file using curl.

curl -X POST -F "[email protected]" "http://localhost:3000/"

By default, uploaded files will be stored in collection fs.files with a chunksize of 256k. One can customize the chunksize by passing chunk-size option in the request header.

curl -X POST -F "[email protected]" "http://localhost:3000/" -H "chunk-size:64k"

Valid chunk-size options are ['1k', '4k', '16k', '64k', '256k', '1m', '4m']

multipart-mongo's People

Contributors

oreh avatar

Stargazers

Ng Tze Yang avatar

Watchers

Ng Tze Yang avatar James Cloos 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.