text QUploader组件的扩展使其能够上传文件抛出Firebase存储

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text QUploader组件的扩展使其能够上传文件抛出Firebase存储相关的知识,希望对你有一定的参考价值。


import { QUploaderBase } from 'quasar'

export default {
  props: ['refStorage'],
  name: 'FirebaseUploader',
  data () {
    return {
      uploading: '',
      uploadTask: {}
    }
  },

  mixins: [QUploaderBase],

  computed: {
    isIdle() {
      return !this.uploading
    },

    isUploading() {
      return this.uploading
    }
  },

  methods: {
    abort() {
      if (!this.disable && this.isUploading) {
        this.uploadTask.cancel()
        this.uploading = false
      }
    },

    upload() {
      if (this.disable || !this.queuedFiles.length) {
        return
      }

      const queue = this.queuedFiles.slice(0)
      this.queuedFiles = []

      queue.forEach(file => {
        this.uploadFile(file)
      })
    },
    
    uploadFile(file) {
      const ref = this.refStorage
      this.uploadTask = ref.child(file.name).put(file)
      
      this.uploadTask.on(
        'state_changed',
        snapshot => {
          this.uploading = true
          this.uploadSize = snapshot.totalBytes
          this.uploadedSize = snapshot.bytesTransferred
        },
        error => {},
        () => {
          this.uploadTask.snapshot.ref.getDownloadURL().then(downloadURL => {
            this.uploading = false
            this.$emit('uploaded', downloadURL)
          })
        }
      )
    }
  }
}
<template>
  <q-uploader-firebase :ref-storage="refStorage" @uploaded="setImage" />
</template>

<script>

import QUploaderFirebase from '...'
export default {
  components: {
    QUploaderFirebase
  },
  data() {
    return {
      refStorage: firebase.storage.ref('images')
    } 
  },
  methods: {
    setImage(downloadURL) {
      // ...
    }
  }
}

以上是关于text QUploader组件的扩展使其能够上传文件抛出Firebase存储的主要内容,如果未能解决你的问题,请参考以下文章

text 分段上传协议扩展

下载然后上传图像而不存储它

如何在 Flash 中创建 Flex Display 组件?

如何使用Jmeter在Web服务中上传和编码(base64)文件

使用apache的fileupload组件上传文件怎么解决编码问题?

可扩展的图像存储