Sails队长无声地失败

时间:2017-05-18 03:41:56

标签: sails.js skipper

使用从docs复制和粘贴的代码,上传不会引发任何错误(事实证明,如果出现错误,它将返回HTTP状态500以及错误信息)。

req.file('avatar').upload(function (err, uploadedFiles) {
    if (err) return res.send(500, err);
    return res.json({
        message: uploadedFiles.length + ' file(s) uploaded successfully!',
        files: uploadedFiles
    });
});

但是,uploadedFiles的结尾长度为0。

我正在使用本地磁盘适配器。

有什么可能出错的猜测?

1 个答案:

答案 0 :(得分:2)

来自skipper github。它不会将空内容长度分类为错误。它只是跳过所有硬体解析工作。

if (
  // If we have a content-length header...
  !_.isUndefined(req.headers['content-length']) &&
  // And the content length is declared to be zero...
  (req.headers['content-length'] === 0 || req.headers['content-length'] === '0')) {
  // Then we set the body to any empty object
  // and skip all this body-parsing mishegoss.
  req.body = {};
  return next();
}
相关问题