Closed smartvault-kcorrell closed 10 years ago
Could you please provide plupload based extension sample? Generic File API works fine with Kango 1.3 and the latest Firefox. Content script:
var div = document.createElement("div");
div.innerHTML = '<input id="files" type="file" multiple/><output id="result" />';
$(div).appendTo(document.body);
//Check File API support
if(window.File && window.FileList && window.FileReader)
{
var filesInput = document.getElementById("files");
filesInput.addEventListener("change", function(event){
var files = event.target.files; //FileList object
var output = document.getElementById("result");
for(var i = 0; i< files.length; i++)
{
var file = files[i];
//Only pics
if(!file.type.match('image'))
continue;
var picReader = new FileReader();
picReader.addEventListener("load",function(event){
var picFile = event.target;
var div = document.createElement("div");
div.innerHTML = "<img class='thumbnail' src='" + picFile.result + "'" +
"title='" + picFile.name + "'/>";
output.insertBefore(div,null);
});
//Read the image
picReader.readAsDataURL(file);
}
});
}
else
{
kango.console.log("Your browser does not support File API");
}
The problem is not with the File object. It's the absence of the prototype. Content script:
alert( "File.prototype: " + File.prototype );
Add the following code to make File.prototype work on new Firefox versions:
try {
if (window.wrappedJSObject.File.prototype) {
File.prototype = window.wrappedJSObject.File.prototype;
}
if (window.wrappedJSObject.FileReader.prototype) {
FileReader.prototype = window.wrappedJSObject.FileReader.prototype;
}
}
catch (error) {
}
We had some help already with exposing the File.prototype in the content script space in Firefox 17+ for plupload. However, we have since upgraded our plupload and Kango versions, and we have run into the problem again in Firefox 26.
In particular, this code no longer works in Kango version 1.3.3 while in Firefox 26:
After some inspection, it seems these objects have been dropped from window.wrappedJSObject somehow.