在 Firebase 存储中同时创建文件和设置元数据

Creating a file and settimng metadata at the same time in Firbase Storage

我目前正在开发一个使用 Firebase 存储来存储文件的 React 应用程序。 我的问题是:我想创建一个文件并将元数据附加到它,然后再将其存储在 Firebase 存储上; 据我所知,现在我必须

  1. 将文件保存在存储中创建文件 ref
  2. 获取该文件的引用,设置元数据并上传。

有没有办法将这 2 个步骤合并为 1 个步骤?

提前感谢您的宝贵时间

如 Cloud Storage for Firebase doc 中所述,“上传文件时,您还可以为该文件指定元数据”。

// Create file metadata including the content type
var metadata = {
  contentType: 'image/jpeg',
};

// Upload the file and metadata
var uploadTask = storageRef.child('images/mountains.jpg').put(file, metadata);