Firebase存储下载我上传的原始文本,而不仅仅是网址 [英] Firebase storage download the raw text I uploaded and not just the url
问题描述
我使用提供的样本上传了一个原始字符串
'Test'到firebase存储这里,并成功完成。但是,当我尝试下载我上传的字符串,使用下面的示例,显然他只是如何从 firebase下载数据的例子存储
它返回字符串文件的URL。
storageRef.child('path / to / string')。getDownloadURL()。then(function(url){
//我得到的网址当然是
})。catch(function(error){
//处理任何错误
});
如何从回调 url
它是'Test'(我上传的字符串)。
简单的答案就是在Web Storage SDK只能获取表示该数据的下载URL。您需要使用 XMLHttpRequest
(或等价物)下载文件:
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; //应该有文本
}
XMLHttp.open(GET,url,true); //对于异步
XMLHttp.send(null);
})。catch(function(error){
/ /处理存储
})中的任何错误;
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.)
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
});
这篇关于Firebase存储下载我上传的原始文本,而不仅仅是网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!