I'm making a simple application that will upload a file a server that has been dragged and dropped onto a canvas.
Here's a small sample of what the drag and drop code looks like:
var files = event.dataTransfer.files;
var formData = new FormData();
formData.append('files', files);
Using the debug tools, I know that files
is correctly defined.
Then, I make the request:
var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload', true);
xhr.send(formData);
But my server, running Node JS, gets an empty response body:
var express = require('express');
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({
extended: false
}));
app.post('/upload', function(req, res) {
console.log(req.body.files);
res.end();
});
I tried debugging on both the client and server side, but I can't figure it out. Although, it seems weird to me that the formData
object looks like:
FormData {append: function}
__proto__: FormData
Why isn't the appended files
object showing up?
Any insight as to what the problem is would be greatly appreciated!