From 927782ef2264a0a2cd7302b2fd88e8097bbd54b3 Mon Sep 17 00:00:00 2001 From: Pedro Lopes Date: Wed, 26 Aug 2020 19:15:11 -0300 Subject: [PATCH] upload image on profile view --- src/views/public/Register.vue | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/views/public/Register.vue b/src/views/public/Register.vue index 6db231a..4137b8f 100644 --- a/src/views/public/Register.vue +++ b/src/views/public/Register.vue @@ -6,7 +6,7 @@ - mdi-account-circle + mdi-account-circle avatar @@ -45,6 +45,7 @@ import { mapActions } from 'vuex' import uploadImageToFirebase from '../../util/firebase' +import axios from 'axios'; export default { @@ -55,6 +56,9 @@ export default { switch1: false, + uploadUrl:process.env.VUE_APP_UPLOAD_URL, + + form: { name: null, @@ -89,12 +93,6 @@ export default { const files = event.target.files this.targetFile = event.target.files[0] - // const imgFirebaseURL = await uploadImageToFirebase(targetFile) - // console.log('uploadddddddddddddddddddddddddddddddd') - // console.log(imgFirebaseURL) - - - const fileReader = new FileReader() fileReader.addEventListener('load', () => { this.src = fileReader.result }) fileReader.readAsDataURL(files[0]) @@ -110,20 +108,18 @@ export default { this.validation() - const imgFirebaseURL = await uploadImageToFirebase(this.targetFile) - console.log('uploadddddddddddddddddddddddddddddddd') - console.log(imgFirebaseURL) // ESTÁ DANDO VAZIO POIS NÃO ESTÁ ESPERANDO O RETORNO DA URL DA FUNÇÃO "uploadImageToFirebase()" - this.form.avatar = imgFirebaseURL - - this.loading = true + const fd = new FormData(); + fd.append('photo', this.targetFile); + + const uploadedFile = await axios.post(this.uploadUrl + '/upload/image', fd).then(resp => { this.form.avatar = resp.data }) + this.form.avatar = uploadedFile + // this.loading = true this.$toast.info('Estamos fazendo seu registo.', 'Hey', { position: "topCenter" - }) - - const imgURL = await uploadImageToFirebase(this.form.avatar) + }) - this.form.avatar = imgURL + console.log(this.form) const register = await this.register(this.form)