本文介绍了无法在'URL'上执行'createObjectURL':的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Safari中显示以下错误。
Display Below error in Safari.
Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
我的代码是:
function createObjectURL(object) {
return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);
}
这是我的图片代码:
function myUploadOnChangeFunction() {
if (this.files.length) {
for (var i in this.files) {
if (this.files.hasOwnProperty(i)) {
var src = createObjectURL(this.files[i]);
var image = new Image();
image.src = src;
imagSRC = src;
$('#img').attr('src', src);
} }
} }
推荐答案
当我传递给 createObjectURL
原始数据时,我遇到了同样的错误:
I experienced same error, when I passed to createObjectURL
raw data:
window.URL.createObjectURL(data)
它必须是 Blob
,文件
或 MediaSource
对象,而不是数据本身。这对我有用:
It has to be Blob
, File
or MediaSource
object, not data itself. This worked for me:
var binaryData = [];
binaryData.push(data);
window.URL.createObjectURL(new Blob(binaryData, {type: "application/zip"}))
另请查看MDN以获取更多信息:
Check also the MDN for more info: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL
这篇关于无法在'URL'上执行'createObjectURL':的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!