0

I uploaded a raw String 'Test' to the firebase storage using the sample provided here and it went through successfully.

But when I tried to "download" the string I uploaded, using the sample below, apparently he only example on how to download data from firebase storage it returns the url of the string file.

storageRef.child('path/to/string').getDownloadURL().then(function(url) {
  // I get the url of course
}).catch(function(error) {
  // Handle any errors
});

How do I get the contents of the file from the callback url which is 'Test' (The string I uploaded.)

jofftiquez
  • 7,548
  • 10
  • 67
  • 121

1 Answers1

3

The short answer is that in the Web Storage SDK you can only get a download URL that represents that data. You'll need to "download" the file using an XMLHttpRequest (or equivalent):

storageRef.child('path/to/string').getDownloadURL().then(function(url) {
  var XMLHttp = new XMLHttpRequest();
  XMLHttp.onreadystatechange = function() { 
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
      var response = xmlHttp.responseText; // should have your text
  }
  XMLHttp.open("GET", url, true); // true for asynchronous 
  XMLHttp.send(null);
}).catch(function(error) {
  // Handle any errors from Storage
});
Mike McDonald
  • 15,609
  • 2
  • 46
  • 49