2

当我们检测到由于不应该保存文件而导致的某些约束时,是否可以在船长上传功能中取消文件保存?

我有一段这样的代码:

req
  .file("multimedia")
  .upload({
    // Destination directory
    dirname : dirName,
    // Maximum image size in bytes
    maxBytes : MAX_IMG_SIZE,
    saveAs : function(__newFileStream, cb) {
      Blueprint.create(req, res, function(err, newInstance) {
        if (err) {
          // This call breaks down the application
          // This is the place where saving file should be canceled
          cb(err);
        } else {
          // Image name will be image Id
          cb(null, newInstance.id.toString());
        }
      });
    }
  },
  function whenDone(err, uploadedFiles) {
    if (err) {
      res.negotiate(err);
    } else {
      res.ok();
    }
  });

在 saveAs 函数中,我首先将记录保存在数据库中,然后使用从保存的记录返回的 id 等名称保存上传的文件。但是,如果保存到数据库不成功(例如由于验证错误),我该如何取消在磁盘上保存文件并进一步传递该错误?

4

0 回答 0