Socket
Socket
Sign inDemoInstall

@aws-sdk/s3-presigned-post

Package Overview
Dependencies
8
Maintainers
5
Versions
361
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @aws-sdk/s3-presigned-post

[![NPM version](https://img.shields.io/npm/v/@aws-sdk/s3-presigned-post/latest.svg)](https://www.npmjs.com/package/@aws-sdk/s3-presigned-post) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/s3-presigned-post.svg)](https://www.npmjs.com/package/@


Version published
Weekly downloads
278K
increased by39.02%
Maintainers
5
Created
Weekly downloads
 

Changelog

Source

3.357.0 (2023-06-21)

Features

  • client-emr: This release introduces a new Amazon EMR EPI called ListSupportedInstanceTypes that returns a list of all instance types supported by a given EMR release. (9875d03)
  • client-inspector2: This release adds support for Software Bill of Materials (SBOM) export and the general availability of code scanning for AWS Lambda functions. (d57a444)
  • client-mediaconvert: This release introduces the bandwidth reduction filter for the HEVC encoder, increases the limits of outputs per job, and updates support for the Nagra SDK to version 1.14.7. (dd88e3f)
  • client-mq: The Cross Region Disaster Recovery feature allows to replicate a brokers state from one region to another in order to provide customers with multi-region resiliency in the event of a regional outage. (983be32)
  • client-sagemaker: This release provides support in SageMaker for output files in training jobs to be uploaded without compression and enable customer to deploy uncompressed model from S3 to real-time inference Endpoints. In addition, ml.trn1n.32xlarge is added to supported instance type list in training job. (f0ede90)
  • client-transfer: This release adds a new parameter StructuredLogDestinations to CreateServer, UpdateServer APIs. (8f0033b)
  • clients: automatic blob type conversions (#4836) (60ec921)

Readme

Source

@aws-sdk/s3-presigned-post

NPM version NPM downloads

This package provide a function generating URL and fields. Users without AWS credentials can use the URL and fields to to make a POST request to S3. The documentation for the server side feature can be found in S3 API Reference. Please read related sections for more context.

Import

JavaScript Example:

const { createPresignedPost } = require("@aws-sdk/s3-presigned-post");
const { S3Client } = require("@aws-sdk/client-s3");

ES6 Example

import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
import { S3Client } from "@aws-sdk/client-s3";

Create a POST Policy

You can optionally attach a policy to a presigned post. It specifies a list of conditions that the request must meet. For example:

const Conditions = [{ acl: "public-read" }, { bucket: "johnsmith" }, ["starts-with", "$key", "user/eric/"]];

Visit S3 POST documentation for supported policy elements. If you include a condition, you must specify the valid value in the Fields parameter as well. A value will not be added automatically to the fields dictionary according to the conditions.

Generate a Presigned Post

Users can generate required url and fields for POST request:

const client = new S3Client({ region: "us-west-2" });
const Bucket = "johnsmith";
const Key = "user/eric/1";
const Fields = {
  acl: "public-read",
};
const { url, fields } = await createPresignedPost(client, {
  Bucket,
  Key,
  Conditions,
  Fields,
  Expires: 600, //Seconds before the presigned post expires. 3600 by default.
});

The Bucket, Key and other values in Fields must meet the conditions specified in Conditions. The Key can also contain ${filename} that will be automatically replaced by the name of the file provided. See the S3 reference for more information.

Post File using HTML Form

You can also post a file with HTML form:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  </head>
  <body>
    <!-- Copy the 'url' value returned by createPresignedPost() -->
    <form action="URL_VALUE" method="post" enctype="multipart/form-data">
      <!-- Copy the 'fields' key:values returned by S3Client.generate_presigned_post() -->
      <input type="hidden" name="key" value="VALUE" />
      <input type="hidden" name="AWSAccessKeyId" value="VALUE" />
      <input type="hidden" name="policy" value="VALUE" />
      <input type="hidden" name="signature" value="VALUE" />
      File:
      <input type="file" name="file" /> <br />
      <input type="submit" name="submit" value="Upload to Amazon S3" />
    </form>
  </body>
</html>

Post File using FormData in Node.js

In Node.js, use form-data package to post a file:

const { createReadStream } = require("fs");
const FormData = require("form-data");

const form = new FormData();
Object.entries(fields).forEach(([field, value]) => {
  form.append(field, value);
});
form.append("file", createReadStream("path/to/a/file"));
form.submit(url, (err, res) => {
  //handle the response
});

FAQs

Last updated on 21 Jun 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc