相关疑难解决方法(0)

尝试上传到 aws s3 存储桶时收到 400 错误请求

我在我的服务器上签署 URL 并将其发送回客户端,它工作正常。这是该函数的外观

const aws = require('aws-sdk'),
    config = require('config'),
    crypto = require('crypto');


module.exports = async function(file_type) {

    aws.config.update({accessKeyId: config.AWS_ACCESS_KEY, secretAccessKey: config.AWS_SECRET_KEY})

    const s3 = new aws.S3();

    try {
        if (!file_type === "image/png") {
            return ({success: false, error: 'Please provide a valid video format'});
        }
        let buffer = await crypto.randomBytes(12);

        let key = buffer.toString('hex');

        let options = {
            Bucket: config.AWS_S3_BUCKET,
            Key: key,
            Expires: 60,
            ContentType: file_type,
            ACL: 'public-read',
        }

        let data = await s3.getSignedUrl('putObject', options);
        console.log('data was', data)
        return ({ …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3 amazon-web-services node.js reactjs

4
推荐指数
2
解决办法
6719
查看次数