我有以下代码:
const { S3Client } = require('@aws-sdk/client-s3');
const { createPresignedPost } = require('@aws-sdk/s3-presigned-post');
router.post(
'/sign-s3', async (req, res, next) => {
const { name, type } = req.body;
const client = new S3Client({
region: 'eu-central-1',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
});
const params = {
Bucket: process.env.S3_BUCKET_NAME,
Expires: 60,
Conditions: [
['content-length-range', 100, 5242880],
{ 'Content-Type': 'image/jpeg' },
],
Fields: {
key: `blog/${name}`,
'Content-Type': type,
success_action_status: '201',
},
};
try {
const data = await createPresignedPost(client, params);
return …Run Code Online (Sandbox Code Playgroud)