Как заменить базовый URL-адрес изображения по умолчанию при загрузке изображения в редакторе Froala? - PullRequest
0 голосов
/ 18 сентября 2018

Я новичок в редакторе Froala и застрял в разделе изображений.Я хочу загрузить выбранное изображение в firebase, а затем заменить URL-адрес изображения по умолчанию на URL-адрес, полученный из firebase.До сих пор я успешно загрузил изображение в firebase и получил URL.но теперь застрял на том, как изменить URL-адрес изображения по умолчанию на новый URL-адрес.

вот мой код

$('div#editor_flora').froalaEditor(
{
    htmlAllowedAttrs: [
        'title', 'href', 'alt', 'src', 'style', 'onclick', 'data-toggle',
        'data-target', 'id', 'class'

    ],
    // Set the image upload parameter.

    imageMaxSize: 5 * 1024 * 1024,

    // Allow to upload PNG and JPG.
    imageAllowedTypes: ['jpeg', 'jpg', 'png']
})
.on('froalaEditor.image.beforeUpload', function (e, editor, images) {
    // Return false if you want to stop the image upload.
    console.log(images)
    firebase.auth()
    const ref = firebase.storage().ref();
    const file =images[0]

    console.log("file name")
    console.log(file.name)
    if (file !== undefined) {
        const name = (+new Date()) + '-' + file.name;
        const metadata = {
            contentType: file.type
        };
        const task = ref.child("images/" + name).put(file, metadata);
        task
            .then(snapshot => snapshot.ref.getDownloadURL())
            .then((url) => {

                console.log(url)
                // imageManagerLoadURL:url
                // image.insert(url)
                editor.popups.hideAll();


            })
    }
})
.on('froalaEditor.image.uploaded', function (e, editor, response) {
    // Image was uploaded to the server.
    alert('sdfasdfsdf')
    console.log(editor)
    console.log(response)
    console.log('Image was uploaded to the server')

})
.on('froalaEditor.image.inserted', function (e, editor, $img, response) {
    // Image was inserted in the editor.

    console.log(e)
    console.log(editor)
    console.log($img)
    console.log('Image was inserted in the editor')

})
.on('froalaEditor.image.replaced', function (e, editor, $img, response) {
    // Image was replaced in the editor.


    console.log('Image was replaced in the editor')
})
.on('froalaEditor.image.error', function (e, editor, error, response) {
    // Bad link.
    if (error.code == 1) {
        console.log('Bad link')
    }

    // No link in upload response.
    else if (error.code == 2) {
        console.log('No link in upload response')

    }

    // Error during image upload.
    else if (error.code == 3) {
        console.log('Error during image upload')

    }

    // Parsing response failed.
    else if (error.code == 4) {
        console.log('Parsing response failed')

    }

    // Image too text-large.
    else if (error.code == 5) {
        console.log('age too text-la')

    }

    // Invalid image type.
    else if (error.code == 6) {
        console.log('Invalid image type')

    }

    // Image can be uploaded only to same domain in IE 8 and IE 9.
    else if (error.code == 7) {
        console.log('Image can be uploaded only to same domain in IE 8 and IE 9')

    }

    // Response contains the original server response to the request if available.
})

, пожалуйста, помогите мне выйти из этой проблемы.Я потратил много времени на поиск и решение этой проблемы.

...