简体   繁体   English

使用FormData将文件上传到Sails.js服务器

[英]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.

相关问题 使用Dropzone.js使用Sails.js 0.10和Skipper上载多个文件 - Uploading multiple files with Sails.js 0.10 and Skipper using Dropzone.js 如何判断 POST 请求是否包含要在 Sails.js 中上传的文件? - How to tell if a POST request contains files for uploading in Sails.js? 使用带有Sails.js v0.10的Skipper上传文件 - 如何检索新文件名 - Uploading files using Skipper with Sails.js v0.10 - how to retrieve new file name Sails.js在使用skipper将文件上传到MongoDB之前检查内容(有效文件,图像大小调整等) - Sails.js checking stuff before uploading files to MongoDB with skipper (valid files, image resizing etc) 使用ng-file-upload指令将文件上载到sails.js服务器 - Uploading a file with ng-file-upload directive to a sails.js server 使用sails.js在nodejs服务器中上传文件 - upload a file in nodejs server with sails.js node.js:在sails.js中使用multer上传文件 - node.js:file upload using multer in sails.js 使用dojox.form.Uploader和FormData上载文件 - Uploading files using dojox.form.Uploader and FormData 使用AJAX上传文件而不使用FormData(IE9) - Uploading files using AJAX without FormData (IE9) Sails.JS使用skipper上传文件,访问原始文件名和动态上传路径 - Sails.JS File uploads using skipper, accessing original file name and dynamic upload path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM