Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
express-filestack
Advanced tools
Express middleware to pipe multipart/form-data (upload) requests to Filestack
Express middleware to pipe multipart/form-data (upload) requests to Filestack.
This middleware allows you to create an intermediary endpoint for multipart/form-data
requests which uploads your file to Filestack.
npm install express-filestack
yarn add express-filestack
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 strigified JSON object if the upload is succcessful.
Note: For cases when the API key is wrong, res.filestack
will contain a response string and not stringified JSON.
const express = require('express')
const filestack = require('express-filestack')
const app = express()
app.post('/uploads', filestack, (req, res) => {
try {
// Successful response will have a stringified JSON from Filestack
// '{"url": "https://cdn.filestackcontent.com/vP3jekLSdahlMH1g47vy", "size": 4950, "type": "image/png", "filename": "Screen Shot 2018-08-02 at 8.40.25 PM.png"}'
const data = JSON.parse(res.filestack)
res.json({ data })
} catch (err) {
// An uncsuccessful response string as a response
// Use an error middleware here or return the response from Filestack
res.json({ error: res.filestack })
}
})
app.listen(5000, () => console.log('Example app listening on port 5000!'));
The name of the input
field should be set as fileUpload
.
<form action="/uploads" method="post" enctype="multipart/form-data">
<input type="file" name="fileUpload">
</form>
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.post('/uploads', filestack({ uploadUrl }), (req, res) => {
res.json({
data: JSON.parse(res.filestack)
})
})
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.
const uploadUrl = 'https://www.filestackapi.com/api/store/S3?key=4kBkTCq6QTqjkcprFyUN4c'
const omitHeaders = [ 'authorization', 'x-something' ]
app.post('/uploads', filestack({ uploadUrl, omitHeaders }), (req, res) => {
res.json({
data: JSON.parse(res.filestack)
})
})
When set to true
, debug logs will be enabled. Or you can set DEBUG=express-filestack
environment variable to see all debugging information.
app.post('/uploads', filestack({ debug: true }), (req, res) => {
res.json({
data: JSON.parse(res.filestack)
})
})
Contributions are welcome. If you encounter any problem, file an issue here.
FAQs
Express middleware to pipe multipart/form-data (upload) requests to Filestack
The npm package express-filestack receives a total of 0 weekly downloads. As such, express-filestack popularity was classified as not popular.
We found that express-filestack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.