0.2.0 • Published 9 years ago
express-filebin v0.2.0
express-filebin
Upload files and create download links.
Currently supports Amazon S3 and local disk storage.
Environment Variables
General
HANDLERHandler could be one ofs3,localBASE_URL(*)Base url for public access, defaults to http://localhostUPLOAD_PATHUpload path, defaults to/uploadsDOWNLOAD_PATH(*)Download path, defaults to/download/:id(*) only works with
HANDLER=local
File
FILE__DESTFile destination, defaults to __dirname + '/uploads'FILE__LIMITS__FIELDNAMESIZEMaximum size of field name, defaults to 100FILE__LIMITS__FILESIZEMaximum size of each upload file, defaults to 1024 1024 100 bytes ~= 100 MBFILE__LIMITS__FILESNumber of upload files, defaults to 5FILE__LIMITS__FIELDSNumber of fields, defaults to 5
S3
S3__PRESIGNED__EXPIRESPre-signed download link expire time in seconds, defaults to 1209600 (14 days)S3__ACCESSKEYIDAccess key id for S3S3__SECRETACCESSKEYSecret access key for S3S3__REGIONAWS Region for exampleus-west-2S3__PARAMS__BUCKETBucket name
Local
LOCAL__MAXMax number of files, defaults to 50LOCAL__MAX__AGEMax age of files in seconds, defaults to 3600000 (1000 mins)
Example
app = express();
app.use(filebin({
handler: 's3',
s3Options: {
accessKeyId: '1234',
secretAccessKey: '5678',
endpoint: 'http://localhost:5566',
s3BucketEndpoint: false,
use_ssl: false,
s3ForcePathStyle: true,
params: {
Bucket: 'test-bucket'
}
},
uploadOptions: {
dest: __dirname + '/uploads'
}
}));Response format
- Single file (HANDLER=s3)
{
"fieldname": "firmware.zip",
"physicalPath": "/test/uploads/f6951d0c2b1ce84f56da1fe15d6eb6a5",
"url: "http://localhost:5566/test-bucket/f6951d0c2b1ce84f56da1fe15d6eb6a5?AWSAccessKeyId=1234&Expires=1507650209&Signature=mehx3Ws5fqyoSlMrbbD7WVi%2FOAU%3D"
}- Multiple files (HANDLER=local)
[{
"fieldname": "firmware.zip",
"physicalPath": "/test/uploads/7b56c995b84aefa61c08f820133a7c98",
"url": "http://localhost/download/7b56c995b84aefa61c08f820133a7c98"
}, {
"fieldname": "firmware2.zip",
"physicalPath": "/test/uploads/364285130128f73422d178c2ecbc56d0",
"url": "http://localhost/download/364285130128f73422d178c2ecbc56d0"
}]