Hello,
I tried following the moleculer framework documentation for uploading the file as multipart, by making change in ApiGateway route & setting the aliases with the rest route as mutlipart:service.action. Below is the snap of the ApiGateway settings
{
path: "/api2",
authorization: true, //run method `authorize` before calling handler
// Use bodyparser module
bodyParsers: {
json: false,
urlencoded: false
},
mappingPolicy: "all",
aliases: {
// File upload from HTML multipart form
"POST /v2.dataviewer.upload": "multipart:v2.dataviewer.upload"
},
// Route level busboy config.
// More info: https://github.com/mscdex/busboy#busboy-methods
busboyConfig: {
limits: { files: 1 }
// Can be defined limit event handlers
// `onPartsLimit`, `onFilesLimit` or `onFieldsLimit`
},
// Call before `broker.call`
onBeforeCall(ctx, route, req) {
this.addExtraMetaData_beforeCall(ctx, route, req);
},
// Call after `broker.call` and before send back the response
onAfterCall(ctx, route, req, res, data) {
this.addExtraMetaData_afterCall(
ctx,
route,
req,
res,
data
);
//do stuff
let urlSplit = req.url.split('/'),
services = '/' + urlSplit[1] + '/' + urlSplit[2];
// Increment this metric (api.usage.total) counter by 1 everytime a particular api is called.
// This metric is used in grafana to see how many times this api is called by a individual user
this.broker.metrics.increment("api.usage.total", {
endpoint: req.url,
services: services,
login: ctx.meta.user.login,
version: this.version
}, 1);
//!important, has to return data after doing stuff
return data;
},
onError(req, res, err) {
// Increment this metric (api.error.total) counter by 1 everytime there is an error in API call.
// This metric is used in grafana to see how many times API failed for user level
this.formatAndSendError(res, err);
this.broker.metrics.increment("api.error.total", {
endpoint: req.url,
login: req.$ctx.meta.user ? req.$ctx.meta.user.login : "@unauthorized",
version: this.version
}, 1);
}
}
But still in the service layer I'm getting undefined in the service Action method
Hello, I tried following the moleculer framework documentation for uploading the file as multipart, by making change in ApiGateway route & setting the aliases with the rest route as mutlipart:service.action. Below is the snap of the ApiGateway settings
But still in the service layer I'm getting undefined in the service Action method
Any help is highly appreciated.