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

sri4node-attachments

v0.1.5

Published

A standard implementation to support attachments on sri4node resources.

Downloads

5

Readme

sri4node-attachments

Support module to easily add support for attachments (BLOBs) on SRI resources implemented with sri4node. Currently supports storing attachments in a local folder, or on Amazon S3.

Example

// First configure the module
//
var winston = require('winston'); // For logging.
var sri4nodeAttachments = require('sri4node-attachements');
var attachments = sri4nodeAttachments.configure(winston, {
  s3key: process.env.S3_KEY,
  s3secret: process.env.S3_SECRET,
  s3bucket: process.env.S3_BUCKET
});
//
// In your sri4node resource configuration
//
...
customroutes: [
    attachments.customRouteForDownload('/people'),  // support GETting
    attachments.customRouteForUpload('/people')     // support PUTting
]
...

Next you can use PUT on /people/{guid}/filename.jpg to create and update attachments. Any filename can be used. The attachement is associated with /people/{guid} And you can do GET on the same URL to retrieve your attachment.

Configuration

  • s3key : Use this key to connect to S3.
  • s3secret : Use this secret to connect to S3.
  • s3bucket : Store the attachments in this S3 bucket.
  • s3region : Connect to this S3 region. Default eu-west-1.
  • folder : If you want to store the attachements in a local folder specify an existing folder here.
  • tempFolder : Must be a writable directory. Used for intermediate storage of uploaded attachments.
  • maximumFilesizeInMB : The maximum size for file uploads, in megabytes.

Adding custom middleware

You can add custom middleware (one or an array of them) in the routes that are handling your attachments :

...
customroutes: [
    attachments.customRouteForUpload('/people', myMiddleware),
    attachments.customRouteForDownload('/people', [ myMiddleware1, myMiddleware2 ])
]
...

You can use this to update for example a database table, or a JSONB column on the affected resource, etc..

Future

  • Add a flexible way to support meta information on the attachments.
  • Provide an sri4node afterread function to allow adding $$atachments listing available attachments.
  • Provide an sri4node afterdeletefunction to make it easy to delete attachments when a resource is removed.
  • In the future storage for smaller items in postgres may be added.
  • ...