读取流未执行触发/捕获错误

问题描述 投票:0回答:1

我正在尝试创建一个读取流以使用Cloudinary的上载流功能,我也正在使用resumable.js对初始文件进行分块,而创建读取流则工作得很好(因为整个文件都可以很好地写入。)读取流/ cloudinary上传功能似乎根本没有触发或失败。

router.post("/upload", (req, res, next) => {
  console.log("the params are.. ", req.body);

  resumable.post(req, function(
    status,
    filename,
    original_filename,
    identifier
  ) {
    if (status === "done") {
      let timestamp = new Date().getTime().toString();
  //stich the chunks

  var s = fs.createWriteStream(timestamp + filename);
  resumable.write(identifier, s);

  var upload_stream = cloudinary.uploader.upload_stream(
    { tags: "basic_sample" },
    function(err, image) {
      console.log();
      console.log("** Stream Upload");
      if (err) {
        console.warn(err);
      }
      console.log("* Same image, uploaded via stream");
      console.log("* " + image.public_id);
      console.log("* " + image.url);
      waitForAllUploads(timestamp + filename, err, image);
    }
  );

    fs.createReadStream(timestamp + filename)
    .pipe(upload_stream)
    .on("error", err => {
      console.log(err);
    });

  s.on("finish", function() {
    // Stream upload
    console.log("ive finished...");
    // delete chunks
    setTimeout(() => {
      resumable.clean(identifier);
    }, 1000);
  });
}
res.send(status);
  });
});

这里是我正在使用的资源:

https://github.com/cloudinary/cloudinary_npm/blob/master/samples/basic/basic.js

https://github.com/mrawdon/resumable-node

javascript node.js cloudinary
1个回答
0
投票
fs.createReadStream(timestamp + filename)接受文件路径,但看起来您也正在传递时间戳。此外,未定义waitForAllUploads。您可以仅使用Node和Cloudinary来测试以下代码。
© www.soinside.com 2019 - 2024. All rights reserved.