我正在运行一个小型的Node.js Express应用程序,该应用程序使用 multer-s3-transform 和Sharp软件包以及 simple-thumbnail 软件包来上传图像和视频。到我的S3存储桶我的代码非常适合图像,传递图像,对其进行锐利调整大小,然后继续将其上传到我的存储桶中。但是,我正在尝试使用简单缩略图将视频缩略图上传到我的s3存储桶,但是我不确定如何将流传递到此包的genThumbnail函数。在文档中指出,您可以向/从其中传递流,想知道如何执行此操作。
关注的包裹:
https://github.com/gmenih341/multer-s3
https://github.com/ScottyFillups/simple-thumbnail
const express = require('express');
const app = express();
const aws = require('aws-sdk');
const multerS3 = require('multer-s3');
const sharp = require('sharp');
const ffmpeg = require('ffmpeg-static');
const genThumbnail = require('simple-thumbnail');
let s3 = new aws.S3({});
let upload = multer({
storage: multerS3({
s3: s3,
bucket: MY_BUCKET,
acl: 'public-read',
cacheControl: 'max-age=31536000',
shouldTransform: true,
contentType: multerS3.AUTO_CONTENT_TYPE,
transforms: [{
id: 'original',
key: function (req, file, cb) {
let fileName = Date.now().toString();
cb(null, fileName + '-original')
},
transform: function (req, file, cb) {
if (file.mimetype == 'video/mp4') {
//HERE IS THE PROBLEM, first two arguments of genThumbnail can take in a stream.Readable, and stream.Writable
cb(null, genThumbnail(null, null, '150x100', { path: ffmpeg.path }))
} else {
//THIS WORKS (WHEN NOT VIDEO)
cb(null, sharp().jpeg())
}
}
}]
})
});
app.post('/upload', upload.array('theFile'), (req, res) => {
//response
});
我希望 genThumbnail()创建缩略图,并像处理Sharp()的图像一样继续沿文件流传递。