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

@scloud/lambda-fileupload

v0.0.10

Published

Functions uploading/downloading files with Lambda/API Gateway where the file size is greater than the payload limit.

Downloads

145

Readme

Lambda / API Gateway file uploads

There's a limit to the request size you can send to API Gateway (10M) and Lanbda (6M). This means you can't upload / download files where the size might be greater than this limit.

Even if files are smaller, you'll need to do some work to configure binary media types and base-64 encode the data. See https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html

If you've done some Googling, you'll likely have come across the concept of pre-signed URLs, which allow your application to upload/download directly to/from s3. This package aims to make implementing that pattern as easy as possible.

There's no magic here, these are straightforward wrapper functions that eliminate complexity and give you what you're likely to need.

This is intended to provide you with the operations you'll mostly need most of the time and, if you have an edge-case, example code you can reuse that helps you get what you need done more easily.

Release notes

  • 0.0.10: actions/setup-node@v4 and Node lts
  • 0.0.8: actions/checkout@v4 and Node 20.x
  • 0.0.7: Fix default validity windows of getUrl and putUrl to match the documentation.

Functions

This package offers 3 functions, GET/PUT (good for programmatic access) and POST (which is good for HTML forms, but a little more involved)

GET/PUT

Most useful for programmatic assess:

import { getUrl, putUrl } from '@scloud/lambda-fileupload';

// Upload
const put = await putUrl('mybucket', 'key/of/destination/file.png');
const fileData = await // Read in your file
await axios.put(put, fileData);

// Download
const get = await getUrl('mybucket', 'key/of/destination/file.png');
const response = await axios.get(get);
const imageData = response.data; // Handle downloaded content

POST

Most useful for HTML forms:

import { postUrl } 'from @scloud/lambda-fileupload'

// Form field values
const post = await postUrl('mybucket', 'key/of/destination/file.png');

console.log(post.url);
// https://mybucket.s3.eu-west-2.amazonaws.com/

console.log(post.fields);
// {
//   bucket: 'mybucket',
//   'X-Amz-Algorithm': 'AWS4-HMAC-SHA256',
//   'X-Amz-Credential': '...',
//   'X-Amz-Date': '20230813T115102Z',
//   key: 'key/of/destination/file.png',
//   Policy: '...',
//   'X-Amz-Signature': '...'
}

The URL goes in the form action and the fields need to be added as hidden fields in the form, with the 'file' field at the end.

For more detail on using a pre-signed post see: https://www.npmjs.com/package/@aws-sdk/s3-presigned-post#user-content-post-file-using-html-form