Last active
November 26, 2020 17:18
-
-
Save amalj07/6d3412951fabf9106a8f1f9b8138d079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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