Open hnguyen48206 opened 3 years ago
For anyone who's having the same situation with what I mentioned above, here is my work-around at this moment though I'm not so certain why. In short, delaying the logic in _closeInternal method in writestream.js does the trick.
GridWriteStream.prototype._closeInternal = function (cb) {
console.log('abc jhjkjhj')
if (!this._opened) return;
if (this._closing) return;
this._closing = true;
var self = this;
// Here is where you want to delay with a settimeout
setTimeout(() => {
self._store.close(function (err, file) {
self._closing = false;
self._opened = false;
if (err) return self._error(err);
self.emit('close', file);
if (cb) cb();
});
}, 2000);
}
Hi everyone, I'm new to Nodejs and MongoDB in general and currently trying to use GridFs as a file storage. My setup is basically using busboy to handle the multipart form-data and then check when the uploading file exceeds the pre-specified file size limit, then I will use destroy method to cancel the stream and using the close event to check if I need to remove uploaded chunks from gridfs. All works just fine for the very first time file upload but not from the second one onward. The destroy method is called but 'close' event is not which means I do not get the callback to see if chunks deletion is needed.
My development environment (node version: 10.16.3):