Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload Multiple field files different name and different location file dest in multer and feathersjs #1358

Open
Juancesar123 opened this issue May 18, 2019 · 3 comments

Comments

@Juancesar123
Copy link

// Initializes the pengukuhan-kawasanservice on path/pengukuhan-kawasan`
const createService = require('feathers-sequelize');
const createModel = require('../../models/pengukuhan-kawasan.model');
const hooks = require('./pengukuhan-kawasan.hooks');

module.exports = function (app) {
const Model = createModel(app);
const paginate = app.get('paginate');
const multer = require('multer');
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './public/fileshp')
},
filename: function (req, file, cb) {
cb(null, file.originalname);
}
})
const upload = multer({ storage: storage});
const options = {
Model,
paginate
};

// Initialize our service with any options it requires
app.use('/pengukuhan-kawasan', upload.single('file_shp'), upload.single('dokumen_sk'),createService(options));

// Get our initialized service so that we can register hooks
const service = app.service('pengukuhan-kawasan');

service.hooks(hooks);
};
`
hello , im problem with feathersjs using multer, im upload multiple field files using different name fields and different location dest . how use multiple fields in feathersjs and multer. thank you :)

@webafra
Copy link

webafra commented Jun 1, 2020

same problem .

@bertho-zero
Copy link
Collaborator

You use upload.single, it's for a single file upload.

Try

app.use(
  '/pengukuhan-kawasan',
  upload.fields([
    { name: 'file_shp', maxCount: 1 }, // available at `req.files.file_shp[0]`
    { name: 'dokumen_sk', maxCount: 1 } // available at `req.files.dokumen_sk[0]`
  ]),
  createService(options)
);

@webafra
Copy link

webafra commented Jun 4, 2020

You use upload.single, it's for a single file upload.

Try

app.use(
  '/pengukuhan-kawasan',
  upload.fields([
    { name: 'file_shp', maxCount: 1 }, // available at `req.files.file_shp[0]`
    { name: 'dokumen_sk', maxCount: 1 } // available at `req.files.dokumen_sk[0]`
  ]),
  createService(options)
);

yes , i use this but if send other file ( no file_shp or dokumen_sk ) , multer resolved error !!!

2 - It is not possible to validate the file ( rar, zip, pdf ) and image ( jpg, png, gif ) separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants