0

I am implementing a store file service and using multer for handling upload files.Normally if I upload files from browsers to the service, it works properly. But now the service also needs to handle files which are sent from another server.

On that server, let call it the middle server, I also use multer for hanlding upload files, I build a custom storage here to stream the files to the file service immediately instead of storing them temporary by diskstorage or bufferstorage. I followed the guide from Piping stream from busboy to request post to do it

Everything works very well as I expected, the files are stored successfully on the file service server. But I get a problem that I can not handle: the file service doesn't send a response to the middle server. After adding a lot of logs in multer, I found out that onFinished function never runs the callback:

function done (err) {
      if (isDone) return
      isDone = true

      req.unpipe(busboy)
      drainStream(req)
      busboy.removeAllListeners()

      onFinished(req, function () { 
        console.log('onFinished callback -- multer completes the work, next');
        next(err) 
      })
    }

I tried to dig in on-finished module, found out that the callback will be called, if the request is end or finish, but it never happened.

So if possible, please help me to resolve this.

Thanks,

0 Answers0