0

Is there any way to rename or download the file from the firebase storage?

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

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.
lawchihon
  • 13
  • 1
  • 7
  • 1
    There is no built-in API to rename/move files on Firebase Storage. See http://stackoverflow.com/questions/38601548/how-to-move-files-with-firebase-storage – Frank van Puffelen Sep 06 '16 at 21:44

2 Answers2

2

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.

2) you'll want to enable CORS on your objects, see: Firebase Storage and Access-Control-Allow-Origin

Community
  • 1
  • 1
Mike McDonald
  • 15,609
  • 2
  • 46
  • 49
0

Trigger click with javascript...

<a href="downloadURL" download="filename.txt">download filename.txt</a> 
Endless
  • 34,080
  • 13
  • 108
  • 131
  • I may not be clear enough. What I mean is to download the file as a file variable like blob in javascript – lawchihon Sep 06 '16 at 20:10
  • With this the file will be renamed to filename.txt – Endless Sep 06 '16 at 20:12
  • But now when it's more clear what you want... You should try to get [CORS enable](http://enable-cors.org/) if you can. Otherwise you need something like a [CORS proxy](https://www.google.com/search?q=CORS%20proxy&rct=j) – Endless Sep 06 '16 at 20:15