Summary
Creates a new object URL, whose lifetime is tied to the document
in the window on which it was created. The new object URL represents the specified File
object.
Syntax
objectURL = window.URL.createObjectURL(file);
fileis aFileobject indicating the file to create a object URL for.objectURLis the generated object URL. The entire contents of the specified file are represented by the text of the URL.
Note: This method is prefixed in Chrome and Webkit as window.webkitURL.createObjectURL().
Example
Notes
Each time you call createObjectURL(), a new object URL is created, even if you've already created one for the same file. Each of these must be released by calling window.URL.revokeObjectURL()
when you no longer need them. Browsers will release these automatically when the document is unloaded; however, for optimal performance and memory usage, if there are safe times when you can explicitly unload them, you should do so.
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|
| Basic support | 8 | 4 | --- | --- | Nightly build |
| Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | ? | ? | ? | ? | ? |
Mozilla Developer Network