Busboy is the middleware I'm using to upload a file. Using an html form inside Chrome, I can upload files (using the 'file' event) but when an android client tries to upload a file, it doesn't trigger the 'file' event, it triggers the 'field' event instead.
Here the code snippet I am using on the server side:
import express from 'express';
import busboy from 'connect-busboy';
const app = express();
const busUpload = (req, res)=> {
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
saveTo = `${destination}/${filename}`;
Log('uploading to', saveTo);
file.pipe(fs.createWriteStream(saveTo));
// file is saved successfully.
});
req.busboy.on('field', function(key, value, keyTruncated, valueTruncated) {
// I guess 'value' contains the file, but how do I save it? what is the name of file?
});
req.busboy.on('finish', function() {
Log('upload completed');
// res.writeHead(200, {'Connection': 'close'});
res.json({sucess: true});
});
// req.pipe(req.busboy);
};
app.use('/uploads', busboy({immediate: true}), busUpload)
What's the difference? What should I tell the android developer to change in his request? Or how can I save the file inside the handler of the 'field' event?