npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-filestack

v1.0.0

Published

Express middleware to pipe multipart/form-data (upload) requests to Filestack

Downloads

9

Readme

express-filestack

npm npm JavaScript Style Guide

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 = 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 unsuccessful 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!'));

Caveats

  • The name of the input field should be set to fileUpload. This example in the Filestack docs uses fileUpload as the key to upload a file.

    <form action="/uploads" method="post" enctype="multipart/form-data">
      <input type="file" name="fileUpload">
    </form>
  • 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.post('/uploads', filestack({ uploadUrl }), (req, res) => {
  res.json({
    data: JSON.parse(res.filestack)
  })
})

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.post('/uploads', filestack({ uploadUrl, omitHeaders }), (req, res) => {
  res.json({
    data: JSON.parse(res.filestack)
  })
})

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.post('/uploads', filestack({ debug: true }), (req, res) => {
  res.json({
    data: JSON.parse(res.filestack)
  })
})

Contributing

Contributions are welcome. If you encounter any problem, file an issue here.

License

MIT