feathers icon indicating copy to clipboard operation
feathers copied to clipboard

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

Open Juancesar123 opened this issue 6 years ago • 3 comments

// 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 :)

Juancesar123 avatar May 18 '19 04:05 Juancesar123

same problem .

webafra avatar Jun 01 '20 18:06 webafra

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)
);

bertho-zero avatar Jun 03 '20 15:06 bertho-zero

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.

webafra avatar Jun 04 '20 05:06 webafra