简体   繁体   English

使用JavaScript从Firebase存储重命名或下载文件

[英]Rename or Download File from Firebase Storage in JavaScript

Is there any way to rename or download the file from the firebase storage? 有什么办法可以从Firebase存储中重命名或下载文件?

I don't see the rename method nor download method. 我看不到重命名方法或下载方法。

I tried to download the file by the url and it doesn't work at all 我尝试通过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();

It returns 它返回

No 'Access-Control-Allow-Origin' header is present on the requested resource.

Two things here: 这里有两件事:

1) you want to use the getDownloadURL() method ( docs ) to get a public download URL, that way you can simply drop your item in an <img> tag, allow users to click on it to download it, or use an XMLHttpRequest to get the bytes. 1)您想使用getDownloadURL()方法( docs )获取公共下载URL,这样您就可以简单地将项目放在<img>标记中,允许用户单击它进行下载,或使用XMLHttpRequest获取字节。

2) you'll want to enable CORS on your objects, see: Firebase Storage and Access-Control-Allow-Origin 2)您需要在对象上启用CORS,请参阅: Firebase存储和Access-Control-Allow-Origin

使用javascript触发点击...

<a href="downloadURL" download="filename.txt">download filename.txt</a> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM