Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.
/ nodefu Public archive

An Express middleware to easily save files sent through multipart/form-data on the disk

License

Notifications You must be signed in to change notification settings

cesarvargas00/nodefu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

multipart/form-data saving to disk made easy.

Requirements

Install

npm install nodefu

Usage

var express = require('express')
var nodefu  = require('nodefu')

var app = express()
app.use(nodefu())

You can access the files in the request object and save them to disk like this:

req.files.fieldName.toFile(path,[filename],callback)
  • fieldName: the name of the input field on your html
  • path: string containing the save path
  • filename: optional parameter string that specifies the name of the file ( if none is passed, the file name will be the same )
  • callback: callback function with err and data attributes, respectively

And to save the uploaded files to mongodb, first you have to specify the mongodb path when using the middleware:

app.use(nodefu('mongodb://127.0.0.1:27017/test'))

And now you can call this method from the request object:

req.files.fieldName.toMongo([filename],callback)
  • fieldName: the name of the input field on your html
  • filename: optional parameter string that specifies the name of the file ( if none is passed, the file name will be the same )
  • callback: callback function with err and data attributes, respectively

You can also access data passed through multipart/form-data other than files using

req.fields.otherFieldName
HTML
<form id="uploadForm" enctype="multipart/form-data" action="/actionRoute" method="post">
    <input type="file" name="fieldName"></input>
    <input type="text" name="otherFieldName"></input>
    <input type="submit" name="submit" value="Upload File"></input>
</form>
Angular

If you are using angular, I recommend using the ng-file-upload module. You can check it out on here.

->♥<-

About

An Express middleware to easily save files sent through multipart/form-data on the disk

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published