【问题标题】:keditor convert blob generated image URL to base64keditor 将 blob 生成的图像 URL 转换为 base64
【发布时间】:2018-01-11 12:59:07
【问题描述】:

我正在为我的文档使用 keditor。我的问题是图像是作为 blob 生成的,我无法知道它们的存储位置,因此当将文件转换为另一种格式时,图像会丢失。

带有 blob 的示例图像标记:

<img src="blob:http://localhost/7b0e82ab-445b-4866-b8b5-09b4881a0544" width="100%" height="" style="display: inline-block;">

我希望我能找到一种使用 PHP 或 JS 将其转换为 blob 的方法。

我也找到了这篇文章,但没有提供解决方案:

JS convert blob url to Base64 file

【问题讨论】:

    标签: javascript php jquery html ckeditor


    【解决方案1】:

    在您的代码中的某处,您引用了必须获取 blob url 的 blob,将其传递给 FileReader,如下所示:

    // Just an example file
    var blob = new Blob(['abc'], {type: 'text/plain'})
    
    var reader = new FileReader()
    reader.onload = function() {
      var base64data = reader.result
      console.log(base64data)
    }
    reader.readAsDataURL(blob)

    【讨论】:

      【解决方案2】:

      使用 AJAX:

      $.ajax({
            method: "GET",
            url: "blob:http://127.0.0.1:8000/e89c5d87-a634-4540-974c-30dc476825cc",
            dataType: "binary",
          }).done(function( data ) {
              var reader = new FileReader();
              reader.readAsDataURL(data); 
              reader.onloadend = function() {
                   var base64data = reader.result;
                   console.log(base64data)
              }
          });
      

      尚未对此进行测试,但应该为您指明正确的方向。

      【讨论】:

        猜你喜欢
        • 2019-11-18
        • 1970-01-01
        • 2014-04-06
        • 1970-01-01
        • 1970-01-01
        • 2015-08-04
        • 2017-07-11
        • 2017-01-05
        相关资源
        最近更新 更多