I have tried this way sample code. I can successfully upload the file, but before that I have to validate file type and allow only *.csv files.
Asked
Active
Viewed 587 times
2 Answers
0
You can use mime node module for that. https://www.npmjs.com/package/mime

Atul Agrawal
- 1,474
- 5
- 22
- 41
0
You must complement sample code as follows:
Edit
server/datasources.json
, add to storage datasources theallowedContentTypes
field, an array of mime types that you want support... "storage": { "name": "storage", "connector": "loopback-component-storage", "provider": "filesystem", "root": "/var/www/storage", "maxFileSize": "52428800", "allowedContentTypes":["text/csv", "application/vnd.ms-excel"] } ...
This step is optional but is a good practice. The error can be handled in callback, also can add a remote hook in the container model file
common/models/container.js
module.exports = function (container) { container.afterRemoteError('upload', function (ctx, next) { //do any with ctx.error }); }

Community
- 1
- 1

Dennys González
- 46
- 1
- 5