загрузка больших видеофайлов в s3 с помощью express.js - PullRequest
1 голос
/ 25 октября 2019

Я загружаю медиа файлы на s3 с помощью Express и Multer-S3. это нормально работает, если я загружаю файлы размером менее 10 МБ. если я загружаю больше, чем 7 МБ (я проверял. Если я загружу около 30 МБ, это не удастся), это выдает ошибку. 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)

faqFileUpload

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}`)
        }
    })
 })

uploadFileHandler

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

...