0

我已转换上传并将其存储为缓冲区。当我写这个缓冲区时,我得到一个路径错误。

TypeError:路径必须是字符串或缓冲区

  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)
          });
        });
      });
    });
  });
4

1 回答 1

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, () => {

但首先要确保该流实际上是按照上面链接中的描述创建的。

于 2018-03-28T13:20:34.233 回答