express-restful-fileman
A restful express router for manage(upload multi-files and remove files) file on web.
Usage
npm install express-restful-fileman --save
const fileman = const app = app
Options
fileman(dirpath: string, { token?: string, enableDelete?: boolean, browserViewRoute?: string, browserViewOptions?: object })
dirpath
(required): The file man's work directory.token
(optional): Check request's authorization header when token is be setting. (default: null)pass
(optional): The function for response success data. (default:(res, data = 'ok') => {res.status(200).json({ code: 200, data })}
)fail
(optional): The function for response fail data. (default:(res, error) => {...}
)generateFilename
(optional): The function for generating storing filename. (default:({name, md5}) => name || md5
)enableDelete
(optional): Whether enable the delete's API. (default: false)browserViewRoute
(optional): The browserView route. (see BrowserView Middleware)browserViewOptions
(optional): The browserView Middleware Options. (see BrowserView Middleware)
Web API
POST
Method: Add the files which is belongs path using multipart/form-data
.
-
Disable decompress (by default)
The request path means path of directory, and each file's filename means relative path.requestSet path to be
dir/?force=true
to guarantee overwriting old file.
-
Enable decompress (by append querystring
?decompress=true
)
The request path means path of directory too.request
DELETE
Method: Remove the files which is belongs path.
eg. /dir/abc
can clear the dirpath/dir/abc
.
BrowserView Middleware (>=v3)
The Browser Upload UI.
Usage
restful-fileman
Mix in const fileman = const express = const join = const app = app// GET: `/fileman` would servers browser UI.
Standalone
const browserView = const express = const app = app
Options
serverUrl
: The fileman's server url, eg.http://example.com/fileman
. (default:location.origin + location.pathname
)serverUrlVisible
: Whether the serverUrl input ui control is visible. (default:false
)token
: Fileman server's token. (default:null
)namespace
: The relative path you want to upload, eg.root/abc
. (default:''
)force
: see Web API (default:false
)decompress
: see Web API (default:false
)