2

我正在使用 express 和 multer-s3 将媒体文件上传到 s3。如果我上传小于 10 mb 的文件,它工作正常。如果我上传大于 7mb(我测试过。如果我上传大约 30mb 它将失败),它会给出错误。cannot determine length of string

我正在上传.mp4文件

错误信息

Exception has occurred: Error
Error: Cannot determine length of [object Object]
    at byteLength (projectpath/node_modules/aws-sdk/lib/util.js:200:26)
    at ManagedUpload.adjustTotalBytes (projectpath/node_modules/aws-sdk/lib/s3/managed_upload.js:299:25)
    at ManagedUpload.configure (projectpath/node_modules/aws-sdk/lib/s3/managed_upload.js:122:10)
    at new ManagedUpload (projectpath/node_modules/aws-sdk/lib/s3/managed_upload.js:93:10)
    at features.constructor.upload (projectpath/node_modules/aws-sdk/lib/services/s3.js:1087:20)
    at S3Storage.<anonymous> (projectpath/node_modules/multer-s3/index.js:182:26)
    at projectpath/node_modules/multer-s3/index.js:68:10
    at FileStream.<anonymous> (projectpath/node_modules/multer-s3/index.js:47:5)
    at Object.onceWrapper (events.js:286:20)
    at FileStream.emit (events.js:198:13)
    at FileStream.EventEmitter.emit (domain.js:448:20)
    at FileStream.Readable.read (_stream_readable.js:491:10)
    at flow (_stream_readable.js:957:34)
    at resume_ (_stream_readable.js:938:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

我的代码

正文解析器配置

app.use(bodyparser.urlencoded({ extended: true, limit: '1024mb' }));
app.use(bodyparser.json({}));

文件路径

router.route('/faqvideoupload')
    .post(faqFileUpload.array('files', 1), uploadFileHandler)

常见问题文件上传

module.exports.faqFileUpload = multer({
    storage: multerS3({
        s3: s3,
        acl:  'public-read',
        bucket: process.env.BUCKET_NAME,
        contentDisposition: 'inline',
        // contentLength: 1 * 1024 * 1024 * 1024,
        contentType: multerS3.AUTO_CONTENT_TYPE,
        metadata: function (req, file, cb) {
            cb(null, { fieldName: file.fieldname, });
        },
        key: function (req, file, cb) {
            // console.log(file, 23244324)
            cb(null, `faqs/videos/filename}`)
        }
    })
 })

上传文件处理程序

async function uploadFileHandler(req, res){
    try {
        let files = req.files.map((img)=> {
            return {
                key : img.key, location : img.location, type: img.mimetype
            }
        })
        return res.json({
            success : true,
            files
        })
    } catch (error) {
        return res.json({
            success: false,
            message: error.message
        })
    }
} 

我需要更改 s3 存储桶本身的任何设置吗?

我还读到我必须 contentLength 但这也行不通。

我正在使用 t2.micro ec2 和 eb

4

0 回答 0