Closed apmcodes closed 3 years ago
Services can only be used with app.use
not method specific Express handlers.
app.use('/upload',
uploader,
// another middleware, to transfer the received file to feathers
// multer generates file for uploaded file and body for form data
function (req, res, next) {
req.feathers.file = req.file; // for upload file method file
req.feathers.body = req.body; // for paste method data emails
next();
},
BlobService({ Model: blobStorage }),
},
);
Thank you @daffl.
With the below code, I can use custom service as well as seperate middleware for POST. Using blobService.create() method inside another middleware.
this.blobService = BlobService(blobServiceOptions);
upload.service.js
// setup blobService
...
blobService = BlobService(blobServiceOptions);
app.post('/upload',
uploader,
// another middleware, to transfer the received file to feathers
// multer generates file for uploaded file and body for form data
function (req, res, next) {
req.feathers.file = req.file; // for upload file method file
next();
}
async function (req, res, next) {
// setup blobBody = {id, buffer: req.feathers.file.buffer}
...
const response = await blobService.create(blobBody)
...
next();
}
);
app.use('/v1/bulk', new Bulk(options, app));
If we use blobservice in app.post() we get the below error, but not with app.use()
Code
NodeJS version:
v12.22.1