简体   繁体   English

firebase Google Cloud Storage下载URL的文件夹名称变为文件名

[英]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. 我们正在使用Firebase Google Cloud Storage Bucket存储文件。

When the logged in user wants the download the file kept inside certain folder Eg: 123/admin/1469611803143/123.xlsx 当登录的用户想要下载文件时,该文件保存在某个文件夹中,例如: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 生成的网址将为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 当我下载此文件时,文件名将为123%2Fadmin%2F1469611803143%2F123.xlsx

and not 123.xlsx 而不是123.xlsx

We have tried using download attribute to change the file name 我们尝试使用下载属性更改文件名

but this did not change the file name to 123.xlsx 但这并未将文件名更改为123.xlsx

Please HELP 请帮忙

I'm pretty new with firebase but I achieved this with the following code : 我对firebase相当陌生,但是我通过以下代码实现了这一点:

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)
})  

This is (fortunately or unfortunately) intended behavior. 这是(不幸或不幸的是)预期的行为。 Technically, files in Firebase Storage are stored with the full path (so 123%2Fadmin%2F1469611803143%2F123.xlsx is actually the file name--the slashes and percent escaping are part of the name, and are only represented as path separators in the UI), which is how we get this behavior. 从技术上讲,Firebase Storage中的文件以完整路径存储(因此123%2Fadmin%2F1469611803143%2F123.xlsx实际上是文件名-斜杠和百分号转义是名称的一部分,并且仅在UI),这就是我们获得此行为的方式。

We're likely to modify how downloads work in the future (in that we'll truncate the name), but we've been busy fixing other bugs and polishing higher priority pieces. 将来我们可能会修改下载的工作方式(因为我们会截断名称),但是我们一直在忙于修复其他错误并优化优先级更高的片段。

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

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