Demo.prototype.handleFileSelect = function()

in exif-images/public/main.js [50:85]


Demo.prototype.handleFileSelect = function(e) {
  this.fileInput.true = false;
  e.stopPropagation();
  e.preventDefault();
  var file = e.target.files[0];

  // If we were already listening for metadata from a previously uploaded file we stop listening.
  if (this.metadataRef) {
    this.metadataRef.off();
  }

  var metadata = {
    contentType: file.type
  };

  // Save the image on Cloud Storage.
  var filePath = String(Date.now()) + '/' + file.name;
  firebase.storage().ref(filePath).put(file, metadata).then(function(snapshot) {
    console.log('Uploaded', snapshot.totalBytes, 'bytes.');
    var url = snapshot.metadata.downloadURLs[0];
    console.log('File available at', url);
    this.linkContainer.innerHTML = '<a href="' + url + '">/' + filePath + '</a>';
    this.fileInput.disabled = false;
  }.bind(this)).catch(function(error) {
    console.error('Upload failed:', error);
    this.linkContainer.innerHTML = '';
    this.fileInput.disabled = false;
  }.bind(this));

  // Start listening for the metadata which will be added to the Realtime DB.
  this.metadataRef = firebase.database().ref(Demo.makeKeyFirebaseCompatible(filePath));
  this.metadataRef.on('value', function(snapshot) {
    var metadata = snapshot.val();
    this.metadataContainer.innerHTML = metadata ? JSON.stringify(metadata, null, '  ') : '';
  }.bind(this));
};