rowanwins / vue-dropzone

A Vue.js component for Dropzone.js - a drag’n’drop file uploads utility with image previews
https://rowanwins.github.io/vue-dropzone/docs/dist
MIT License
2.02k stars 1.4k forks source link

MulterError: Unexpected field #586

Open cakka-learn opened 3 years ago

cakka-learn commented 3 years ago

I am using Vude-Dropzone + Express.js + Multer. No problem to upload single file, but for multiple file it give me error "MulterError: Unexpected field".

<vue-dropzone
ref="myVueDropzone"
id="customdropzone"
class="text-center"
:options="dropzoneOptions"
@vdropzone-success="successResponse"
></vue-dropzone>

data: function() {
    return {
      dropzoneOptions: {
        url: "http://localhost:3000/api/upload_location/",
        thumbnailWidth: 150,
        maxFilesize: 499,
        timeout: 9000,
        parallelUploads: 5,
        uploadMultiple: true,
        paramName: function() { return 'file'; },
        },
    },
}

Codes in express.js & multer:

const uploadImg = multer({
    storage: '/upload/',
    .....
})

router.post('/uploadPhoto/:id', uploadImg.array('file', 10), Photo.uploadPhoto);

I've tried to change dropzoneOptions to paramName: function() { return 'file'; }, paramName: file,

Change multer to: router.post('/uploadPhoto/:id', uploadImg.array('file', 10), Photo.uploadPhoto); router.post('/uploadPhoto/:id', uploadImg.fields([{ name: 'file', maxCount: 10 }]), Photo.uploadPhoto);

But, no one success.

Any ideas how to solve this problem ?

SE-SalamAQuran commented 3 years ago

I have the same problem here but I am working with ReactJS, I already solved it before with a single upload but it's not working for the array. Any help is appreciated.

alexdarh commented 2 years ago

+1