Skip to content

Instantly share code, notes, and snippets.

@digitarald
Last active December 13, 2015 18:29
Show Gist options
  • Save digitarald/4956057 to your computer and use it in GitHub Desktop.
Save digitarald/4956057 to your computer and use it in GitHub Desktop.
Image selection via Web Activity on Firefox OS
if ('MozActivity' in window) {
document.getElementById('my-file-input').addEventListener('click', function(evt) {
evt.preventDefault();
var picking = new MozActivity({
name: 'pick',
data: {
type: 'image/jpg'
}
});
picking.onsuccess = function() {

// this.result.blob holds the File reference
// Blob and XMLHttpRequest2
// https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data
// Getting the image data
var img = new Image();
img.onload = function() {
// Draw image to canvas for resizing or similar
}
img.src = URL.createObjectURL(this.result.blob);
};
picking.onerror = function () {

console.log('No image!');
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment