[](https://www.npmjs.com/package/@aws-sdk/s3-presigned-post) [](https://www.npmjs.com/package/@
npm install @aws-sdk/s3-presigned-post

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.
JavaScript Example:
``javascript`
const { createPresignedPost } = require("@aws-sdk/s3-presigned-post");
const { S3Client } = require("@aws-sdk/client-s3");
ES6 Example
`javascript`
import { createPresignedPost } from "@aws-sdk/s3-presigned-post";
import { S3Client } from "@aws-sdk/client-s3";
You can optionally attach a policy to a presigned post. It specifies a list of conditions that the request must meet.
For example:
`typescript`
const Conditions = [{ acl: "bucket-owner-full-control" }, { 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.
Users can generate required url and fields for POST request:
`typescript`
const client = new S3Client({ region: "us-west-2" });
const Bucket = "johnsmith";
const Key = "user/eric/1";
const Fields = {
acl: "bucket-owner-full-control",
};
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${filename}
contain that will be automatically replaced by the name of the file provided. See the S3 reference
for more information.
You can also post a file with HTML form:
`html`
In Node.js, use form-data package to post a file:
`typescript
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
});
``