【问题标题】:Problem file naming when dowloading the file下载文件时文件命名问题
【发布时间】:2022-01-07 04:31:14
【问题描述】:

这是我的第一个堆栈帖子,如果有点模糊,请见谅:/

所以基本上我有一个 Angular 项目,后面有 firestore。我有一个云函数,它生成一个 .xlsx 文件并将其上传到我的 fireStorage。

    const path = 'hellothere/excels';
    return workBook.xlsx.writeFile(`/tmp/myExcel.xlsx`).then(() => {
      return storageFb.upload( `/tmp/myexcel.xlsx`,{
        destination: path+'/myExcel.xlsx',
      }
      )
    }).then(() => path);

StorageFb 是我的存储桶。

实际上它正在工作,它在 /hellothere/excels/ 下上传我的 .xlsx 文件,名称为 myExcel.xlsx。但是当我下载它时(通过管理面板或我的 Angular 客户端),它的全名是 hellothere_excels_myExcel.xlsx

这是我的客户端代码:

this.fireStorage.ref('hellothere/excels/myExcel.xlsx').getDownloadURL().subscribe((url) => {
      window.open(url, '_blank');
  });
   return Promise.resolve();

很简单。我知道代码很乱,但我正在测试我能找到的所有解决方案,所以我会把它清理干净

Admin panel path

My file name

所以我有点卡住了,因为我不知道为什么这些文件不会只用“myExcel”名称下载。 如果有人知道你会拯救我的一周啊哈!谢谢!

【问题讨论】:

    标签: node.js angular excel google-cloud-storage firebase-storage


    【解决方案1】:

    您需要设置内容配置来定义文件名。试试看

        const path = 'hellothere/excels';
        return workBook.xlsx.writeFile(`/tmp/myExcel.xlsx`).then(() => {
          return storageFb.upload( `/tmp/myexcel.xlsx`,{
            destination: path+'/myExcel.xlsx',
            contentDisposition: 'filename=myExcel.xlsx'
          }
          )
        }).then(() => path);
    

    【讨论】:

    • 你救了我!非常感谢,我自己不会找到它 :) 我只需要在“元数据”对象下添加“contentDisposition”,就像这样:元数据:{ contentDisposition:“filename=myExcel.xlsx”} 谢谢 :)跨度>
    猜你喜欢
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多