我正在尝试将图像从新的 Firebase 存储下载到本地文件。为此,我使用 Firebase 提供的示例here https://firebase.google.com/docs/storage/ios/download-files#download_to_a_local_file。这是我的代码:
func getTumbnails(imageName: String) {
// Create a reference to the file you want to download
let tumbnailRef = storageRef.child("tumbs/\(imageName)")
// Create local filesystem URL
let localURL: NSURL! = NSURL(string: "file:///local/tumbnails/\(imageName)")
// Download to the local filesystem
let downloadTask = tumbnailRef.writeToFile(localURL) { (URL, error) -> Void in
if (error != nil) {
print(error)
} else {
let data = NSData(contentsOfURL: URL!)
self.data = data!
print(data)
}
}
}
但是当我调用该函数时getTumbnails("image")
我将以下错误打印到控制台:
可选(错误域=FIRStorageErrorDomain代码=-13000“发生未知错误,请检查服务器响应。” UserInfo={object=tumbs/Sunset.png,bucket=********.appspot.com,NSLocalizedDescription =发生未知错误,请检查服务器响应。, ResponseErrorDomain=NSCocoaErrorDomain, NSFilePath=/local/tumbnails, NSUnderlyingError=0x137f629c0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not allowed"}, ResponseErrorCode=513})
我已经发现this https://stackoverflow.com/questions/37470266/error-when-downloading-from-firebase-storage在 stackoverflow 上提问,但这是一个不同的错误(响应代码 518,而我有 513),并且由于我直接使用示例代码,所以这应该可以工作。
有人可以帮帮我吗?
这里的问题是你得到了一个NSPOSIXErrorDomain
错误表明您没有写入该文件的权限file:///local/tumbnails/\(imageName)
,大概是因为该目录(/local
) 不存在,即使存在,您也无权写入它。
我想看一下the docs https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html对于您可以写入的目录列表 - 您可能应该使用/Documents
or /tmp
为了这。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)