Firebase商店:试图存储到本地文件给出错误 [英] Firebase store: trying to store to local file gives an error
问题描述
当我尝试从Firebase存储中存储文件后,我收到以下错误消息:
可选错误域= FIRStorageErrorDomain代码= -13000一个未知的错误发生,请检查服务器响应。UserInfo = {object = ProfilePicture / Jf2dFzI7LZNzQkOkdFfa3UWQJyH2.jpg,bucket = mapit-1333.appspot.com,NSLocalizedDescription =发生未知错误,请检查服务器响应。,ResponseErrorDomain = NSCocoaErrorDomain,NSFilePath = / local / images,NSUnderlyingError = 0x7fc8a080ab50 {Error Domain = NSPOSIXErrorDomain Code = 13Permission denied},ResponseErrorCode = 513})
这是我的代码:
$ p $ let storage = FIRStorage.storage()
let storageRef = storage.referenceForURL(gs://mapit-1333.appspot.com)
let islandRef = storageRef.child(ProfilePicture /+ uid + .jpg)
//创建本地文件系统URL
让localURL:NSURL! = NSURL(string:file:///local/images/island.jpg)
//下载到本地文件系统
let downloadTask = islandRef.writeToFile(localURL){ URL,错误) - >无效
if(error!= nil){
print(error)
} else {
let data = NSData(contentsOfURL:URL!)
self.profileImage .image = UIImage(data:data!)
$ div class =h2_lin>解决方案
这里的问题是,你得到一个 NSPOSIXErrorDomain
错误,表明你没有权限写入 file:/// local / images / \(imageName)
,可能是因为该目录( / local
)不存在即使是这样,你也没有写权限。
我会看看 docs code> / Documents 或 / tmp
。
When I try to store a file from the Firebase storage following the example from the documents I received the following error:
Optional(Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=ProfilePicture/Jf2dFzI7LZNzQkOkdFfa3UWQJyH2.jpg, bucket=mapit-1333.appspot.com, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=NSCocoaErrorDomain, NSFilePath=/local/images, NSUnderlyingError=0x7fc8a080ab50 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}, ResponseErrorCode=513})
Here is my code:
let storage = FIRStorage.storage()
let storageRef = storage.referenceForURL("gs://mapit-1333.appspot.com")
let islandRef = storageRef.child("ProfilePicture/"+uid+".jpg")
// Create local filesystem URL
let localURL: NSURL! = NSURL(string: "file:///local/images/island.jpg")
// Download to the local filesystem
let downloadTask = islandRef.writeToFile(localURL) { (URL, error) -> Void in
if (error != nil) {
print(error)
} else {
let data = NSData(contentsOfURL: URL!)
self.profileImage.image = UIImage(data: data!)
}
}
The issue here is that you're getting an NSPOSIXErrorDomain
error indicating that you don't have permission to write to the file file:///local/images/\(imageName)
, presumably because that directory (/local
) doesn't exist and even if it does, you don't have permission to write to it.
I'd take a look at docs for a list of directories you can write to--you should probably be using /Documents
or /tmp
for this.
这篇关于Firebase商店:试图存储到本地文件给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!