Phi*_*ipp 5 javascript firebase firebase-storage
是否可以在不使用下载功能的情况下读取文件的值?
代替:
storageRef.child('text.txt').getDownloadURL().then(function() {
...
});
Run Code Online (Sandbox Code Playgroud)
就像是:
storageRef.child('text.txt').getValue().then(function(value) {
alert(value)
});
Run Code Online (Sandbox Code Playgroud)
我在 Firebase Storage 中获取文件内容时遇到了同样的问题,但最后,我发现无法直接读取文件内容。不过,我是这样做的。
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
})
Run Code Online (Sandbox Code Playgroud)
重要的是配置 CORS 设置。您可以在此处找到说明。
跳过这条指令让我消耗了很多时间:/
我希望其他人避免同样的错误。谢谢。
| 归档时间: |
|
| 查看次数: |
2337 次 |
| 最近记录: |