express-filestack
Express middleware to pipe multipart/form-data (upload) requests to Filestack.
Why?
This middleware allows you to create an intermediary endpoint for multipart/form-data
requests which uploads your file to Filestack.
Install
npm install express-filestack
yarn add express-filestack
Usage
Set your Filestack upload URL as an environment variable.
FILESTACK_UPLOAD_URL='https://www.filestackapi.com/api/store/S3?key=4kBkTCq6QTqjkcprFyUN4c'
On completion the middleware will attach a filestack
key to the express response object. It can be accessed as res.filestack
. The key will contain a stringified JSON object if the upload is succcessful.
Note: For cases when the API key is wrong or the upload limit is hit, res.filestack
will contain a response string and not stringified JSON.
const express = const filestack = const app = app app;
Caveats
-
The name of the
input
field should be set tofileUpload
. This example in the Filestack docs usesfileUpload
as the key to upload a file. -
All requests for uploading a file should be sent to
https://www.filestackapi.com/api
. Upload won't work without www in the URL ¯\(ツ)/¯.
Options
uploadUrl
Set your Filestack upload URL by passing it through the middleware. This option can only be a string.
const uploadUrl = 'https://www.filestackapi.com/api/store/S3?key=4kBkTCq6QTqjkcprFyUN4c' app
omitHeaders
If you have application specific headers set in the original request omit those headers being sent to Filestack. This option should be an array of string(s).
omitHeaders
is useful if you don't want to send authorization headers that is needed for your application and does not need to be piped to Filestack for security reasons. The original headers will remain intact when going to the next middleware.
const uploadUrl = 'https://www.filestackapi.com/api/store/S3?key=4kBkTCq6QTqjkcprFyUN4c'const omitHeaders = 'authorization' 'x-something' app
debug
When set to true
, debug logs will be enabled. Or you can set DEBUG=express-filestack
environment variable to see all debugging information.
app
Contributing
Contributions are welcome. If you encounter any problem, file an issue here.