我已经转换了上传并将其存储为缓冲区。当我写这个缓冲区时,我得到一个路径错误。
TypeError:path必须是字符串或缓冲区
const adapter = require('skipper-better-s3')(options);
var receiver = adapter.receive({dirname: "/original"});
var upstream = req.file('file');
upstream.upload(receiver, function(err, filesUploaded){
adapter.read(filesUploaded[0].extra.fd, (err, image) => {
Jimp.read(image,function(err,image){
image.resize(600, Jimp.AUTO).quality(60).getBuffer(image.getMIME(),function(err,buffer){
const stream = fs.createReadStream(buffer);
receiver = adapter.receive({dirname: "/thumbs"});
receiver.write(file, () => {
console.log(file.extra)
});
});
});
});
});
答案 0 :(得分:0)
我认为你的答案就在这里:Converting a Buffer into a ReadableStream in nodejs
另外,请检查您的代码,但我发现您有错误:
const stream = fs.createReadStream(buffer);
receiver = adapter.receive({dirname: "/thumbs"});
receiver.write(file, () => {
console.log(file.extra)
});
receiver.write(file,()=> {应该是receiver.write(stream,()=> {
但首先要确保实际按照上面链接中的说明创建了流。