Display Below error in Safari.
Failed to execute 'createObjectURL' on 'URL': No function was found that matched the signature provided.
My Code is:
function createObjectURL(object) {
return (window.URL) ? window.URL.createObjectURL(object) : window.webkitURL.createObjectURL(object);
}
This is my Code for image:
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);
} }
} }
I experienced same error, when I passed to createObjectURL raw data:
window.URL.createObjectURL(data)
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"}))
Check also the MDN for more info: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL
This error is caused because the function createObjectURL is deprecated for Google Chrome
I changed this:
video.src=vendorUrl.createObjectURL(stream);
video.play();
to this:
video.srcObject=stream;
video.play();
This worked for me.
My code was broken because I was using deprecated stuff. It used to be this:
video.src = window.URL.createObjectURL(localMediaStream);
video.play();
Then I replaced that with this:
video.srcObject = localMediaStream;
video.play();
That worked beautifully.
References:
- Deprecated technique: https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL
- Modern technique: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
I had the same error for the MediaStream. The solution is set a stream to the srcObject.
From the docs:
Important: If you still have code that relies on createObjectURL() to attach streams to media elements, you need to update your code to simply set srcObject to the MediaStream directly.
Video with fall back:
try {
video.srcObject = mediaSource;
} catch (error) {
video.src = URL.createObjectURL(mediaSource);
}
video.play();
From: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/srcObject
The problem is that the keys provided in the loop do not refer to the index of the file.
for (var i in this.files) {
console.log(i);
}
The output of the above code is:
0
length
item
But what was expected was:
0
1
2
etc...
Then the error occurs when the browser tries to execute, for example:
window.URL.createObjectURL(this.files["length"])
I suggest implementation based on the following code:
var files = this.files;
for (var i = 0; i < files.length; i++) {
var file = files[i],
src = (window.URL || window.webkitURL).createObjectURL(file);
...
}
I hope this can help someone.
Greetings!
I fixed it downloading the latest version from GgitHub GitHub url
来源:https://stackoverflow.com/questions/27120757/failed-to-execute-createobjecturl-on-url