Skip to content

Instantly share code, notes, and snippets.

@amalj07
Last active November 26, 2020 17:18
Show Gist options
  • Save amalj07/6d3412951fabf9106a8f1f9b8138d079 to your computer and use it in GitHub Desktop.
Save amalj07/6d3412951fabf9106a8f1f9b8138d079 to your computer and use it in GitHub Desktop.
<template>
<div id="app">
<input type="file" ref="file" v-on:change="handleUpload()"/>
<button v-on:click="uploadFile()">Upload</button> <br>
</div>
</template>
<script>
import axios from 'axios'
export default {
data () {
return {
file: ''
}
},
methods: {
handleUpload() {
this.file = this.$refs.file.files[0]
},
uploadFile() {
const formData = new FormData()
formData.append("file", this.file)
axios.post('http://localhost:5000/upload', formData, {
headers: {
"Content-Type": "multipart/form-data"
}
}).then(response => {
console.log(response.data)
}).catch(error => {
console.log(error)
})
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment