问题
I'm trying to save a string as a file to an AWS S3 bucket using the AWS SDK for NodeJS. The PUT request gets succeeded, but the file does not get created in the S3 bucket. Following is a snippet from my code.
const s3 = new S3({ apiVersion: '2006-03-01' });
const JS_code = `
let x = 'Hello World';
`;
// I'm using the following method inside an async function.
await s3.putObject({
Bucket: 'my-bucket-gayashan',
Key: 'myFile.js',
ContentType:'binary',
Body: Buffer.from(JS_code, 'binary')
});
Can someone please help me with this?
回答1:
You should use promise() with await
:
await s3.putObject({...}).promise();
回答2:
You should provide a valid MIME type in the ContentType
field. In your case it should be application/javascript
.
来源:https://stackoverflow.com/questions/49917935/aws-uploading-a-string-as-file-to-a-s3-bucket