0

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

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。

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

对可能出现的问题有任何猜测吗?

4

1 回答 1

2

来自船长 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();
}
于 2017-05-20T10:11:07.223 回答