Created
April 23, 2019 14:38
-
-
Save razbakov/378caedba3f24e3d8336442182528719 to your computer and use it in GitHub Desktop.
Firebase File Uploader for Quasar Framework
This file contains hidden or 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
<script> | |
import { QUploaderBase } from 'quasar' | |
import firebase from 'firebase/app' | |
import 'firebase/storage' | |
import uuid from 'uuid/v4' | |
export default { | |
mixins: [ QUploaderBase ], | |
props: { | |
metadata: Object | |
}, | |
data () { | |
return { | |
progressUpload: 0, | |
file: File, | |
uploadTask: '' | |
} | |
}, | |
methods: { | |
upload () { | |
this.files.forEach(file => { | |
const ref = 'media/' + uuid() | |
const uploadTask = firebase | |
.storage() | |
.ref() | |
.child(ref) | |
.put(file, this.metadata) | |
uploadTask.on( | |
'state_changed', | |
sp => { | |
this.uploadSize = sp.totalBytes | |
this.uploadedSize = sp.bytesTransferred | |
}, | |
null, | |
() => { | |
uploadTask.snapshot.ref.getDownloadURL().then(downloadURL => { | |
this.$emit('upload', { | |
url: downloadURL, | |
id: ref, | |
name: file.name, | |
size: file.size, | |
uploadedDate: new Date(), | |
lastModified: file.lastModified, | |
description: '' | |
}) | |
this.removeFile(file) | |
}) | |
} | |
) | |
}) | |
} | |
} | |
} | |
</script> |
also looking for a Quasar2 implementation, will check this out and see if I can port it
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://quasar.dev/vue-components/uploader#uploading-multiple-files:~:text=5.-,Supporting,-other%20services