Sails.js 表单 post 未提交任何数据

Sails.js form post not submitting any data

最近我在 post 填写表格时遇到了一个不寻常的问题。当没有附件或附件图像文件大小小于 100kb 时,post 形式可以正常工作。但是当我尝试上传一个大于 100kb 的文件时,表单中的任何元素都没有 posted/submitted。当我 console.log() 它给出的值未定义。我不明白是什么导致了这个问题。控制台屏幕上没有显示任何错误。谁能帮忙解决这个问题?

var name = req.param('name');
console.log(name);

我得到的结果是undefined

我在 windows 8.1 上使用 sails v0.10.5。我使用 postgres 作为我的数据库。

req.param方法用于获取url参数、正文参数、查询参数。 ()

如果您使用 multipart/form-data 上传文件,Sails 使用 skipper 解析数据,您可以像下面这样简单地获取文件

req.file('name').upload(function (err, uploadedFiles){
  if (err) return res.send(500, err);
  return res.send(200, uploadedFiles);
});

我建议查看来自 sails 的官方文件上传文档....

http://sailsjs.org/#!/documentation/concepts/File-Uploads

我遵循了这些步骤,它对我有用(在 sails v 0.11 上)。也许你在路上错过了什么?

使用 skipper,您必须将所有输入文件放在表单的末尾。 否则它可能会出错。

最好使用 blueimp jquery 文件上传插件..它有很多功能可以帮助你。

有同样的问题,结果是输入的顺序很重要,就在github skipper页面

这里说

It is important to realize that the benefit above(Text Parameters) relies on a crucial, simplifying assumption: that user agents send any text parameters before the first file parameter in the multipart HTTP request body. For instance, in an HTML form that means putting all of your tags after the other inputs. If you don't want to lay your form out that way, you'll want to use AJAX to submit it instead