Uploading files to Sails.js server using FormData

705 Views Asked by At

I'm using react-dropzone to upload multiple files to a Sails.js server. Since react-dropzone gives me the list of dropped files, I'm appending them to a FormData object. 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. My question is: Does Skipper have any method to handle FormData uploads or I need to use Multer or something like that?

1

There are 1 best solutions below

2
Matheus Dal'Pizzol On

Well... in the end, I was using FormData the wrong way. 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.

// Incorrect
formdata.append('files[]', file)

// Correct
formdata.append('files', file)