不从Firebase存储下载的图像 [英] Images not downloading from Firebase Storage

查看:219
本文介绍了不从Firebase存储下载的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从新的Firebase存储中下载一个图片到本地文件。为此,我使用示例Firebase提供了此处。这是我的代码:

  func getTumbnails(imageName:String){
//创建对文件的引用想要下载
let tumbnailRef = storageRef.child(tumbs / \(imageName))
//创建本地文件系统URL
让localURL:NSURL!下载到本地文件系统
let downloadTask = tumbnailRef.writeToFile(localURL)= NSURL(string:file:///local/tumbnails/ \(imageName))

{(网址,错误) - >如果(错误!=无){
打印(错误)
} else {
let data = NSData(contentsOfURL:URL!)
self.data =数据!
print(data)
}
}
}



<但是,当我调用函数 getTumbnails(image)时,我得到以下错误输出到控制台:

可选(错误域= FIRStorageErrorDomain代码= -13000未知错误发生,请检查服务器响应。UserInfo = {object = tumbs / Sunset.png,bucket = ********。 NSFilePath = / local / tumbnails,NSUnderlyingError = 0x137f629c0 {Error Domain = NSPOSIXErrorDomain Code = 1Operation not permitted},ResponseErrorCode = 513 })



我发现

可以请某人帮忙吗? 问题在于你得到一个 NSPOSIXErrorDomain 错误,表示你没有权限写入文件 file:/// local / tumbnails / \(imageName),大概是因为那个目录( / local )不存在,即使它存在,有权写入它。



我会看看文档中可以写入的目录列表 - 您应该使用 / Documents / tmp 这个。


I am trying to download an image from the new Firebase Storage to a local file. To do this I use the example Firebase provides here. This is my code:

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)
        }
    }
}

But when I call the function getTumbnails("image") I get the following error printed to the console:

Optional(Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=tumbs/Sunset.png, bucket=********.appspot.com, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=NSCocoaErrorDomain, NSFilePath=/local/tumbnails, NSUnderlyingError=0x137f629c0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}, ResponseErrorCode=513})

I have found this question here on stackoverflow, but that is a different error (Response code 518 while I have 513), and since I directly use the sample code, this should just work.

Can someone please help me?

解决方案

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/tumbnails/\(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 the docs for a list of directories you can write to--you should probably be using /Documents or /tmp for this.

这篇关于不从Firebase存储下载的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆