Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

custom uploader handler

Miguel Michelson Martinez edited this page May 4, 2017 · 2 revisions

This is an example on how you can customize uploader (available from version 0.3.5), amazing right ? kudos to @marekolszewski for his contribution.

import { Dante } from 'Dante2/dist/Dante2.js'
import uuidV1 from 'uuid/v1'

let dante2 = new Dante({
  el: 'editor-id',
  image_upload_handler: (file, imageBlock) => {
    const id = uuidV1()
    const promise = firebase.storage.ref().child(`foo-bar/${id}/${file.name}`).put(file)

    promise.on('state_changed', snapshot => {
      imageBlock.updateProgressBar({ lengthComputable: true, loaded: snapshot.bytesTransferred, total: snapshot.totalBytes })
    })

    promise.then(data => {
      imageBlock.uploadCompleted(data.downloadURL)
    }).catch(() => {
      imageBlock.uploadFailed()
    })
  },
  content: ''
})
dante2.render()
Clone this wiki locally