2016-11-07 90 views
0

我使用提供的样本here将原始String'测试'上传到了Firebase存储并且成功完成。Firebase存储下载我上传的原始文本,而不仅仅是网址

但是,当我试图“下载”我上传的字符串,使用下面的示例,显然他只是如何从firebase storage下载数据的例子,它返回字符串文件的url。

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

如何从回调url这是“测试”获得文件的内容(我上传的字符串)。

回答

1

简短的回答是,在网络存储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; // should have your text 
    } 
    XMLHttp.open("GET", url, true); // true for asynchronous 
    XMLHttp.send(null); 
}).catch(function(error) { 
    // Handle any errors from Storage 
}); 
+0

看来,这个现在因为CORS问题开展工作。 :/ – CENT1PEDE

+0

幸运的是:http://stackoverflow.com/questions/37760695/firebase-storage-and-access-control-allow-origin –

+0

有时我忘记了firebase仍然基于谷歌云服务。谢谢迈克! – CENT1PEDE

相关问题