keditor 将 blob 生成的图像 URL 转换为 base64
keditor convert blob generated image URL to base64
我正在为我的文档使用 keditor。我的问题是图像生成为 blob,我无法知道它们的存储位置,因此当将文件转换为另一种格式时,图像会丢失。
带 blob 的示例图片标签:
<img src="blob:http://localhost/7b0e82ab-445b-4866-b8b5-09b4881a0544" width="100%" height="" style="display: inline-block;">
我希望我能找到一种使用 PHP 或 JS 将其转换为 blob 的方法。
我也找到了这个post但是没有提供解决方案:
JS convert blob url to Base64 file
使用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)
}
});
尚未对此进行测试,但应该为您指明正确的方向。
在你的代码中的某个地方,你有一个 blob 的引用,你必须得到你的 blob url,把它传递给 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)
我正在为我的文档使用 keditor。我的问题是图像生成为 blob,我无法知道它们的存储位置,因此当将文件转换为另一种格式时,图像会丢失。
带 blob 的示例图片标签:
<img src="blob:http://localhost/7b0e82ab-445b-4866-b8b5-09b4881a0544" width="100%" height="" style="display: inline-block;">
我希望我能找到一种使用 PHP 或 JS 将其转换为 blob 的方法。
我也找到了这个post但是没有提供解决方案:
JS convert blob url to Base64 file
使用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)
}
});
尚未对此进行测试,但应该为您指明正确的方向。
在你的代码中的某个地方,你有一个 blob 的引用,你必须得到你的 blob url,把它传递给 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)