Skip to content

Commit

Permalink
upload file on profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Lopes committed Sep 1, 2020
1 parent 7f8ba18 commit e498ab8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/components/cpmEventForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default {
address:'',
eventDate:'',
img:'',
user:'1'
user:5
},
name:'',
Expand Down Expand Up @@ -346,7 +346,21 @@ export default {
axios.post(this.url + '/event/create', body)
.then(resp => {
console.log(resp)
if(resp.status == 200){
this.$toast.success('Registro efetuado!', 'Hey', {
position: "topCenter"
})
}
})
.catch(err => {
this.$toast.error('Erro no registro!', 'Putz', {
position: "topCenter"
})
})
}
Expand Down
54 changes: 51 additions & 3 deletions src/views/private/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@
<v-list-item-subtitle>{{user_data.whatsapp}}</v-list-item-subtitle>
</v-list-item-content>

<v-avatar title size="80" color="grey">
<img :src="user_data.avatar" alt="avatar" />
<v-avatar class="cp" @click="onFileSelected" color="orange" size="62">
<v-icon v-if="!src" dark>mdi-account-circle</v-icon>
<img v-else :src="src" alt="avatar">
<input @change="onFilePicked" type="file" class="hiden-input" ref="fileInput" accept="image/*">
</v-avatar>

<v-btn @click="sendForm">
Mandar formulario
</v-btn>

</v-list-item>

<v-card-actions>
Expand Down Expand Up @@ -65,6 +72,12 @@ export default {
},
data: () => ({
src:'',
imageData:'',
uploadUrl:process.env.VUE_APP_UPLOAD_URL,
user_data: {
avatar: '',
name: '',
Expand All @@ -83,6 +96,40 @@ export default {
getMyEvents: 'ProfileVuex/getMyEvents'
}),
onFileSelected(){
this.$refs.fileInput.click()
},
onFilePicked(event){
const files = event.target.files
let fileName = files[0].filename
this.imageData = event.target.files[0]
const fileReader = new FileReader()
fileReader.addEventListener('load', () => { this.src = fileReader.result })
fileReader.readAsDataURL(files[0])
},
async uploadPhoto(){
const fd = new FormData();
console.log(this.imageData)
fd.append('photo', this.imageData)
await this.$http.post(process.env.VUE_APP_UPLOAD_URL + '/upload/image', fd)
.then(resp => {
let result = resp.data
console.log(result) // URL DA IMAGEM AQUI
return result
})
},
async sendForm(){
let imageuploaded = await this.uploadPhoto()
console.log(imageuploaded)
},
async loadUser(){
const user = await this.getUser();
Expand All @@ -97,7 +144,8 @@ export default {
const events = await this.getMyEvents();
this.events = events;
}
},
},
created(){
Expand Down

0 comments on commit e498ab8

Please sign in to comment.