使用新的 Firebase API,您可以将文件从客户端代码上传到云存储。这些示例假定文件名在上传期间是已知的或静态的:
// Create a root reference
var storageRef = firebase.storage().ref();
// Create a reference to 'mountains.jpg'
var mountainsRef = storageRef.child('mountains.jpg');
// Create a reference to 'images/mountains.jpg'
var mountainImagesRef = storageRef.child('images/mountains.jpg');
或者
// File or Blob, assume the file is called rivers.jpg
var file = ...
// Upload the file to the path 'images/rivers.jpg'
// We can use the 'name' property on the File API to get our file name
var uploadTask = storageRef.child('images/' + file.name).put(file);
随着用户上传自己的文件,名称冲突将成为一个问题。如何让 Firebase 创建文件名而不是自己定义文件名?数据库中是否有类似push()
用于创建唯一存储引用的功能?