相关疑难解决方法(0)

存储具有唯一/随机名称的文件

使用新的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 firebase-storage

29
推荐指数
2
解决办法
1万
查看次数

相当于 Firestore 中的 .push ?

我正在尝试将以前使用实时数据库的 firebase 实现转换为使用 firestore,因为我喜欢集合的想法和使用它的好处。

我如何在下面实现 Firestore 等价物?

firebase.database().ref('documentPath').push()
Run Code Online (Sandbox Code Playgroud)

javascript firebase google-cloud-firestore

6
推荐指数
1
解决办法
5245
查看次数

禁止覆盖的 Firebase 存储规则

我不希望用户能够上传存储中已存在的同名新文件,

这是我尝试过但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)

firebase firebase-security firebase-storage

5
推荐指数
1
解决办法
755
查看次数