使用新的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');
Run Code Online (Sandbox Code Playgroud)
要么
// 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);
Run Code Online (Sandbox Code Playgroud)
用户上传自己的文件时,名称冲突将成为一个问题.如何让Firebase创建文件名而不是自己定义?是否有类似push() …
我正在尝试将以前使用实时数据库的 firebase 实现转换为使用 firestore,因为我喜欢集合的想法和使用它的好处。
我如何在下面实现 Firestore 等价物?
firebase.database().ref('documentPath').push()
Run Code Online (Sandbox Code Playgroud) 我不希望用户能够上传存储中已存在的同名新文件,
这是我尝试过但403在上传不存在的文件时仍然得到的结果。
service firebase.storage {
match /b/projectid/o {
match /{allPaths=**} {
allow read;
allow write: if !resource || request.resource.name == resource.name;
}
}
}
Run Code Online (Sandbox Code Playgroud)