> Like you I've written a wrapper around the File api for DND file
> upload (for use in GWT) and you're right there are memory problems...
> what's happening is the files are being read into memory (FileReader)
> which is obviously very inefficient.
That's where create/revokeObjectURL comes in handy. FF4 and Chrome
both
support this method. It allows you to use a local file without having
to load it
into memory and will persist for the life of the document (think
session storage).
var file = event.dataTransfer.files[0],
video = document.createElement("video"),
objURL = window.URL.createObjectURL(file);
video.src = objURL;
Obvisoulsy I've simplified the above example for verbosity. In the
real world Chrome uses
window.webkitURL.createObjectURL() in the latest builds but also had
window.createObjectURL().
So the above code would end up looking something like this.
var file = event.dataTransfer.files[0],
video = document.createElement("video"),
objURL;
if("createObjectURL" in window || "URL" in window &&
"createObjectURL" in window.URL || "webkitURL" in window &&
"createObjectURL" in window.webkitURL) {
if("createObjectURL" in window) {
// Chrome exposes create/revokeObjectURL directly on
window
objURL = window.createObjectURL(file);
} else if("webkitURL" in window) {
// Chrome exposes create/revokeObjectURL on the new
webkitURL API
objURL = window.webkitURL.createObjectURL(file);
} else {
// FF4 exposes create/revokeObjectURL on the new URL API
objURL = window.URL.createObjectURL(file);
}
} else {
// fallback to FileReader for FF3.6
}
video.src = objURL;
-Ryan
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]