Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase Google Cloud storage download URL has folder name which becomes file name

We are using Firebase Google Cloud Storage Bucket to store our files.

When the logged in user wants the download the file kept inside certain folder Eg: 123/admin/1469611803143/123.xlsx

The url generated will be https://firebasestorage.googleapis.com/v0/b/MYWEBSITE.appspot.com/o/123%2Fadmin%2F1469611803143%2F123.xlsx?alt=media&token=whatever_alpa_numeric_token

As I download this file the file name will be 123%2Fadmin%2F1469611803143%2F123.xlsx

and not 123.xlsx

We have tried using download attribute to change the file name

but this did not change the file name to 123.xlsx

Please HELP

like image 860
Anant Bhandarkar Avatar asked Jul 27 '16 11:07

Anant Bhandarkar


People also ask

How do I download folders from Firebase Storage?

Once you have a reference, you can download files from Cloud Storage by calling the getBytes() or getStream() . If you prefer to download the file with another library, you can get a download URL with getDownloadUrl() .

Does Firebase Storage URL change?

android - Firebase storage URL keeps changing with new token - Stack Overflow. Collectives™ on Stack Overflow – Centralized & trusted content around the technologies you use the most.


1 Answers

I'm pretty new with firebase but I achieved this with the following code :

var storageRef = firebase.storage().ref();
var child = storageRef.child("your path");
var uploadTask = child.put(<file>);

uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
function(snapshot){
// HANDLE TASK PROGRESS
},
function(error){
// HANDLE ERROR
},
function(){
// UPLOAD SUCCESSFULL
  var newMetadata = {
    contentDisposition : "attachment; filename=" + fileName
  }
  child.updateMetadata(newMetadata)
})  
like image 138
diouze Avatar answered Sep 19 '22 21:09

diouze