How to change param name when uploading file using Vue2-Dropzone?

1.6k views Asked by At

When uploading file in Vue2-Dropzone, default param name is "file". But I need to customize it as "upload".

I tried to change it using vdropzone-sending method. But It sends two params "file" and "upload".

Do I need to change backend to accept the param "file"? or Is there a way to customize default param name("file")?

<vue-dropzone v-on:vdropzone-sending="sendingEvent">
</vue-dropzone>
...
methods: {
  sendingEvent (file, xhr, formData) {
    formData.append('upload', file);
  }
}
1

There are 1 answers

1
nibnut On BEST ANSWER

Vue2-Dropzone is a wrapper around Dropzone.js, which has an option to change the parameter name

In order to pass that option to the Vue2-Dropzone component, you use the options prop like so:

<vue-dropzone :options="dropzoneOptions" v-on:vdropzone-sending="sendingEvent"></vue-dropzone>
...
data () {
    return {
        dropzoneOptions: { paramName: "upload" }
    }
}