Open AndrewProbityWeb opened 3 years ago
were you able to resolve this issue? running into something similar
Any solution here? I tried to setup a very simple engine that nearly does nothing and just calls the callback function, which doesn't work. This part is never called and the next function is never called:
busboy.on('close', function () {
readFinished = true
indicateDone()
})
Running to this issue too. Could it be an issue with a newer version of multer?
Without digging to deep into how multer does on the inside, it seems like you need to make sure you consume the stream from the file, otherwise the middleware won't continue on.
Something like this works for me as a POC
import multer from 'multer';
import stream from "node:stream";
...
const storage: multer.StorageEngine = {
_handleFile: function _handleFile(req, file, cb) {
// Create a writeable stream to write to
const dummyStream = new stream.Writable();
dummyStream._write = function (_chunk, _encoding, done) {
console.log('Writing to stream');
done();
};
dummyStream.on('finish', function () {
cb(null, {});
});
// Pipe the files' stream to the dummystream so we consume it
file.stream.pipe(dummyStream);
},
_removeFile: function _removeFile(req, file, cb) {}
};
I have started writing a custom storage engine for a cloud storage provider. The file upload works, but when the upload is finished and the cb is invoked, express.js does not move to the next step on the route, causing the request to that route to hang indefinitely. There are no errors on the server and I can't see anything using debug, but the console.log before the cb() works, the console.log in the routes file doesn't.
This is the code for the CustomStorageEngine. The uploadFile function is just a couple of fetch calls to the cloud provider and some error handling. I am new to node/express, is the callback being called in a promise an issue? If I pass an error to the callback it behaves normally.
This is the code for the route.
Any help would be greatly appreciated