Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Last active June 10, 2019 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/cbe9af37a9e9bfd11f058ffc6a38adbb to your computer and use it in GitHub Desktop.
Save uno-de-piera/cbe9af37a9e9bfd11f058ffc6a38adbb to your computer and use it in GitHub Desktop.
<template>
<div role="form">
<form>
<div class="form-group">
<label class="btn btn-primary">
<i class="fa fa-folder-open-o" aria-hidden="true"></i>&nbsp;Seleccionar un archivo
<input type="file" accept=".pdf" @change="onFileSelected" name="myfile">
</label>
</div>
</form>
</div>
</template>
<script>
export default {
name: "my-component",
methods: {
onFileSelected (event) {
const file = event.target.files[0];
const formData = new FormData();
formData.append("my-file", file);
Vue.http.post(`server-url`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(res => {
//todo ok
},
error => {
//todo mal :P
})
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment