Currently, I am facing an issue with the generation of a presigned post for allowing browser privileges to upload/delete a specific file from a bucket. It appears that the createPresignedPost
function is not populating some of the required fields, whereas getSignedUrl
works fine.
const signedUrl = await new Promise<PresignedPost>( (resolve, reject) => {
this.s3.createPresignedPost({
Bucket: this.env.config.s3.buckets.images,
Fields: { key },
Conditions: [
["content-length-range", 0, 10 * 1024 * 1024]
],
Expires: 3600,
}, (err, preSigned) => { if (err) { reject(err) } else { resolve(preSigned) }});
});
// The code snippet below functions properly but lacks support for object deletion and setting maximum file size constraints.
// const rawUrl = new URL(await this.s3.getSignedUrlPromise('putObject', {
// Bucket: this.env.config.s3.buckets.images,
// Key: key,
// Expires: 3600,
// }));
//
// const signedUrl = {
// url: rawUrl.origin + rawUrl.pathname,
// fields: Object.fromEntries(Array.from(rawUrl.searchParams.entries()))
// };
The generated output by createPresignedPost contains:
{
url: 'https://s3.eu-west-3.amazonaws.com/xxx-images',
fields: {
key: 'incoming/ae83pfxu7kf4dfdv4hbv...' // truncated for brevity
bucket: 'xxx-images',
'X-Amz-Algorithm': 'AWS4-HMAC-SHA256',
// more parameters
}
}
Attempting to PUT a file using these parameters results in an AuthorizationQueryParametersError due to missing necessary information such as X-Amz-SignedHeaders and X-Amz-Expires.
The previous API call seems to include the missing parameters 'X-Amz-SignedHeaders' and 'X-Amz-Expires'. Can anyone point out what mistake I might be making?