viral-vector / vue-upload-image

Configurable image uploader with preview
MIT License
34 stars 17 forks source link

Add additional params to upload request #7

Closed innoflash closed 4 years ago

innoflash commented 5 years ago

The upload request currently is just sending the images, i think if we can add our own params to the request it can work as well.

I just added a params prop to the prop list and attached them just before adding the images to the props i added:

params: { //additional params to send to the server
     type: Object,
     required: false,
     default: {}
 },

To the upload function i added:

//add additional params
for (let [key, value] of Object.entries(this.params)) {
     formData.append(key, value)
}
viral-vector commented 4 years ago

@innoflash a little sketchy on merging this in after i had a chance to review. First i wanted to keep things simple enough that the upload code covers the use of https://github.com/axios/axios & https://github.com/pagekit/vue-resource ; possibly https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API in a later update. The headers, params need to be analogous enough to support both. Possibly a checker/config option to differentiate. For the image type check, that is handled in the fileDrop function for both drag & drop & file input