I struggle on a very simple example for Express.js and Busboy. The code is as simple as possible. That makes it easier for me and others to understand whats going on. the form block:
<form
action="https:// ... this works ..."
enctype="multipart/form-data"
method="post"
>
<label class="up_styles">
<input type="file" name="file" id="somethingTricky"/>
</label>
<br />
<input class="sub" type="submit" value="Submit" />
</form>
and the backend:
const functions = require("firebase-functions");
const Busboy = require('busboy');
const express = require("express");
const app = express();
app.post("/api/fileanalyse", (req, res) => {
const busboy = new Busboy({
headers: req.headers
});
busboy.on('error', function(err) {
console.log(err);
});
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
console.log(fieldname);
console.log(file);
console.log(filename);
console.log(encoding);
console.log(mimetype);
// see other question
file.resume();
});
busboy.on('finish', function() {
console.log('finish');
});
return req.pipe(busboy);
});
exports.App = functions.region("europe-west1").https.onRequest(app);
All the console.logs in the function(fieldname, file, filename, encoding, mimetype) dont work, console.log('finish') works. How do I get the file and the filedata, for example filename and filesize from the request?