I have a service file, and I’m sending a file to the http://localhost:4000/uploads
URL using the “file” field via POST in Postman. However, in my code, context.meta.$multipart
is coming out as undefined
, and the file is not being saved to the public directory.
api.service `
const ApiGateway = require("moleculer-web");
module.exports = {
name: "api",
version: 1,
mixins: [ApiGateway],
settings: {
port: 8080,
path: "/upload",
routes: [
{
path: "",
bodyParsers: {
json: false,
urlencoded: false
},
mappingPolicy: "restrict",
aliases: {
"POST /multi": {
type: "multipart",
// Action level busboy config
busboyConfig: {
limits: {
files: 3
}
},
action: "v1.assets.upload"
},
// File upload from HTML multipart form
"POST /": "multipart:v1.assets.upload",
// File upload from AJAX or cURL
"PUT /": "stream:v1.assets.upload"
},
// Route level busboy config.
busboyConfig: {
limits: {
files: 1
}
}
}
],
assets: {
folder: "./public"
}
}
};
`
assets.service.js `
module.exports = {
name: "assets",
version: 1,
actions: {
upload: {
handler(context) {
console.log("params", context.params.meta);
console.log("context.meta.$multipart", context.meta.$multipart);
}
}
}
};
`
I tried both POST and PUT, and even tested it by creating a website, but I still couldn’t resolve the error. It returns 200 OK
in Postman, but the file is not uploaded, and both console.log statements in the assets.service.js
file are returning undefined
.