moleculerjs / moleculer-web

:earth_africa: Official API Gateway service for Moleculer framework
http://moleculer.services/docs/moleculer-web.html
MIT License
294 stars 119 forks source link

beta6: ctx.meta.$multipart only populated AFTER stream was consumed #154

Closed sysrun closed 4 years ago

sysrun commented 4 years ago

I send a multipart form ti an api endpoint containing a file and several other fields. Before i stream the file to my storageprovider i need to specify some aditional data from the form into the storage (like filetyoe etc.). But ctx.meta.$multipart is an empty object at the time i call my storage function.

So i tested the handler action with the following code:

 return new this.Promise((resolve) => {
      ctx.params.on('data', () => {
        console.log('onData:', ctx.meta.$multipart);
      });

      ctx.params.on('end', () => {
        console.log('onEnd:', ctx.meta.$multipart);
        resolve(ctx.meta);
      });  
    });

Result: The ctx.meta.$multipart is empty while streaming the data and only filled after the stream has ended.

icebob commented 4 years ago

The multipart body is processed one after another. So you should send fields at first and the file at the end.