Sails JSfile upload; 如何检查文件是否是input?
我正在使用Sails JS v11.05。
file upload不是必填字段。
如何检查文件是否上传?
通常,我使用
if (!req.param('param')) { // param does NOT exist - was not uploaded // This does not apply to file input params. } // However, the following will break as it will start a listener (upstream) if (!req.file('param')) { // File was not uploaded }
所有我想知道一个文件是否是一个input,所以我不打扰req.file('文件')。上传(),如果没有上传。
想法?
我无法find这样做,但我们可以使用上游侦听器上传一个空文件,但它会返回并清空上传文件在callback。
请注意,如果运行req.file('file_input'),则可能会在调用侦听器时终止节点服务器。
欲了解更多信息,请参阅https://www.npmjs.com/package/skipper
解决scheme
req.file('file_input').upload(options, function (err, uploadedFiles) { if (err) return cb(err); if (_.isEmpty(uploadedFiles)) return cb(); // A file was attached do });