说明
当试图上传文件到Firestore时,服务器返回404,文件未找到。用于从内存上传文件的代码是在官方文档page中Upload from data in memory
下列出的代码:
// Data in memory
let data = Data()
// Create a reference to the file you want to upload
let riversRef = storageRef.child("images/rivers.jpg")
// Upload the file to the path "images/rivers.jpg"
let uploadTask = riversRef.putData(data, metadata: nil) { (metadata, error) in
guard let metadata = metadata else {
// Uh-oh, an error occurred!
return
}
// Metadata contains file metadata such as size, content-type.
let size = metadata.size
// You can also access to download URL after upload.
riversRef.downloadURL { (url, error) in
guard let downloadURL = url else {
// Uh-oh, an error occurred!
return
}
}
}
存储桶的规则设置为:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2023, 5, 24);
}
}
}
知道是什么问题导致了这个问题吗?
重现问题
使用上述示例代码将数据从内存上传到具有上述规则的Firestore存储桶。
Firebase SDK版本
10.7.0
Xcode版本
14.3
安装方式
CocoaPod
Firebase产品
Firestore
目标平台
iOS
相关日志输出
▿ Optional<Error>
- some : Error Domain=FIRStorageErrorDomain Code=-13010 "Object images/rivers.jpg does not exist." UserInfo={NSUnderlyingError=0x282a27b10 {Error Domain=com.google.HTTPStatus Code=404 "(null)" UserInfo={data={length = 65, bytes = 0x7b0a2020 22657272 6f72223a 207b0a20 ... 2e220a20 207d0a7d }, data_content_type=application/json; charset=UTF-8}}, ResponseErrorCode=404, ResponseErrorDomain=com.google.HTTPStatus, data_content_type=application/json; charset=UTF-8, object=images/rivers.jpg, ResponseBody={
"error": {
"code": 404,
"message": "Not Found."
}
}, NSLocalizedDescription=Object images/rivers.jpg does not exist., data={length = 65, bytes = 0x7b0a2020 22657272 6f72223a 207b0a20 ... 2e220a20 207d0a7d }, bucket=nfluxtv.appspot.com}
链接到GitHub问题:https://github.com/firebase/firebase-ios-sdk/issues/11157
1条答案
按热度按时间rryofs0p1#
事实证明,该代码示例适用于Google Cloud Storage for Firebase。
你不能上传文件到Firestore本身,我不知道:Uploading and downloading files to/from Google Cloud Firestore