[英]Uploading files to Sails.js server using FormData
I'm using react-dropzone to upload multiple files to a Sails.js server. 我正在使用react-dropzone将多个文件上传到Sails.js服务器。 Since react-dropzone gives me the list of dropped files, I'm appending them to a FormData object. 由于react-dropzone提供了已删除文件的列表,因此我将它们附加到FormData对象。 With this, when the request hits the server, the req.file('myfile').upload()
won't work, since I don't have any input[type=file]
on the page and I'm working with AJAX. 这样,当请求到达服务器时, req.file('myfile').upload()
将不起作用,因为我在页面上没有任何input[type=file]
,并且我正在使用AJAX。 My question is: Does Skipper have any method to handle FormData uploads or I need to use Multer or something like that? 我的问题是: Skipper是否有任何方法可以处理FormData上载,还是需要使用Multer或类似的方法?
Well... in the end, I was using FormData the wrong way. 好吧……最后,我以错误的方式使用了FormData。 If anyone out there aren't seeing the files array in the server, just make sure to not use brackets in the key you append to FormData. 如果外面没有人在服务器中看到文件数组,只需确保不要在添加到FormData的键中使用括号。
// Incorrect
formdata.append('files[]', file)
// Correct
formdata.append('files', file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.