feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
15.08k stars 752 forks source link

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

Open Juancesar123 opened 5 years ago

Juancesar123 commented 5 years ago

// Initializes thepengukuhan-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 commented 4 years ago

same problem .

bertho-zero commented 4 years ago

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 commented 4 years ago

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.