是否有办法重命名或从firebase存储下载文件?
我没有看到rename方法和download方法
我尝试通过url下载文件,但它根本不起作用
var blob = null;
var xhr = new XMLHttpRequest();
xhr.open("GET", "downloadURL");
xhr.responseType = "blob";
xhr.onload = function()
{
blob = xhr.response;//xhr.response is now a blob object
console.log(blob);
}
xhr.send();
返回No 'Access-Control-Allow-Origin' header is present on the requested resource.
这里有两点:
1)你想使用getDownloadURL()
方法(docs)来获得一个公共下载URL,这样你就可以简单地把你的项目放在<img>
标签中,允许用户点击它来下载它,或者使用XMLHttpRequest
来获取字节。
2)你想在你的对象上启用CORS,参见:Firebase Storage and Access-Control-Allow-Origin
用javascript触发点击…
<a href="downloadURL" download="filename.txt">download filename.txt</a>