The code:
import { Upload } from "@aws-sdk/lib-storage";
import { s3Client } from "./s3-client";
const bucket = "xxxx";
export async function uploadFile(name: string, content: string) {
const parallelUploads3 = new Upload({
client: s3Client,
params: {
Bucket: bucket,
Key: name,
Body: content,
},
leavePartsOnError: true,
});
await parallelUploads3.done();
}
And I’ve set the CORS rule for this bucket as:
CORSRules: [
{
AllowedHeaders: [ "*" ],
AllowedMethods: [ "GET", "PUT", "DELETE", "HEAD", "POST" ],
AllowedOrigins: [ "*" ],
ExposeHeaders: [ "ETag", "x-amz-*" ]
}
]
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hi there,
Would you mind sharing the exact error that you are getting?
One thing that stands out from the information that you’ve provided so far is that the
s3Client
configuration might not be correct. Here’s an example of how that might look:I could also suggest trying a standard S3 upload to verify if it is working using
PutObject
or similar. Here is a quick example:Let me know how it goes!
Best,
Bobby