最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Read valuecontent of a file from Firebase Storage - Stack Overflow

programmeradmin0浏览0评论

Is it possible to read the value a file without using the download function?

Something instead of:

storageRef.child('text.txt').getDownloadURL().then(function() {
  ...
});

Something like:

storageRef.child('text.txt').getValue().then(function(value) {
  alert(value)
});

Is it possible to read the value a file without using the download function?

Something instead of:

storageRef.child('text.txt').getDownloadURL().then(function() {
  ...
});

Something like:

storageRef.child('text.txt').getValue().then(function(value) {
  alert(value)
});
Share Improve this question edited Feb 2, 2017 at 2:38 AL. 37.8k10 gold badges146 silver badges285 bronze badges asked Feb 2, 2017 at 0:12 PhilippPhilipp 4751 gold badge4 silver badges19 bronze badges 1
  • What is the difference between "read" and "download" in your mind? Just do an XMLHttpRequest get on the download URL. – user663031 Commented Feb 2, 2017 at 4:33
Add a ment  | 

2 Answers 2

Reset to default 7

I had the same trouble with getting content of the file in Firebase Storage, but finally, I found there is no way to read the file content directly. However, I did it like this.

  fileRef.getDownloadURL()
    .then(url => {
      var xhr = new XMLHttpRequest();
      xhr.responseType = 'json'; 
      xhr.onload = function(event) {
        var json= xhr.response;
        console.log(json);      // now you read the file content
      };
      xhr.open('GET', url);
      xhr.send();
    })
    .catch(err => {
        // process exceptions
    })

What is important was configuring the CORS settings. You can find the instructions here.

Skipping this instruction made me consume much time :/
I hope others avoid the same mistakes. Thanks.

There is currently no available function to directly read a file in Firebase Storage in JavaScript without downloading it first.

You can file a Feature Request here, if you think this would be really useful.

发布评论

评论列表(0)

  1. 暂无评论