下载Firebase存储文件设备问题 [英] Downloading Firebase Storage Files Device Issue

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

问题描述

我正在尝试从Firebase存储中下载一个单词文档。在模拟器上,一切都按预期工作。然而在我的设备上,我收到以下错误:

I am trying to download a word document from Firebase storage. On the simulator everything is working as expected. Yet on my device, I get the following error:


可选(错误域= FIRStorageErrorDomain代码= -13000发生未知错误,请检查服务器响应。UserInfo = {object = Bulletin / 2016年10月26日.docx,bucket = southam-college-app.appspot.com,NSLocalizedDescription =发生未知错误,请检查服务器响应。ResponseErrorDomain = NSCocoaErrorDomain,NSFilePath = / tmp / bulletin,NSUnderlyingError = 0x1702590b0 {Error Domain = NSPOSIXErrorDomain Code = 1不允许操作},ResponseErrorCode = 513})

Optional(Error Domain=FIRStorageErrorDomain Code=-13000 "An unknown error occurred, please check the server response." UserInfo={object=Bulletin/26 October 2016.docx, bucket=southam-college-app.appspot.com, NSLocalizedDescription=An unknown error occurred, please check the server response., ResponseErrorDomain=NSCocoaErrorDomain, NSFilePath=/tmp/bulletin, NSUnderlyingError=0x1702590b0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}, ResponseErrorCode=513})

其他帖子我一直在看着似乎没有给我一个工作的答案,我所知道的是,有文件权限的问题,即使我使用推荐的目录(tmp)。

Other posts I have been looking at do not seem to give me a working answer, and all I know is that there is an issue with file permissions, even though I am using the recommended directory (tmp).

这是下载文件的代码

 let Ref_Bulletin = Bulletin.referenceForURL("gs://southam-college-app.appspot.com/Bulletin/\(Today.stringFromDate(NSDate())).docx")

    // Create local filesystem URL
    let localURL: NSURL! = NSURL(string: "file:///tmp/bulletin/today.docx")


        // Download to the local filesystem
        let downloadTask = Ref_Bulletin.writeToFile(localURL) { (URL, error) -> Void in
            if (error != nil) {
                print(error.debugDescription)
                // Uh-oh, an error occurred!
            } else {
                print("Working As Expected")
                self.Web_View.loadRequest(NSURLRequest(URL: localURL))
            }

那么是什么原因导致这个问题,我该如何解决?

So what is causing this problem and how do I fix it?

更新:

所以我试图创建目录,但我被告知我没有权限,即使文档说我可以写tmp。

So I tried to create the directory but I am being told that I don't have permission even though the documentation says I can write to the tmp.


无法创建目录Error Domain = NSCocoaErrorDomain Code = 513您没有权限保存文件今天。文件夹bulltin中的docx。 UserInfo = {NSFilePath = / tmp / bulltin / today.docx,NSUnderlyingError = 0x1702498a0 {错误域= NSPOSIXErrorDomain代码= 1不允许操作}}

Unable to create directory Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file "today.docx" in the folder "bulltin"." UserInfo={NSFilePath=/tmp/bulltin/today.docx, NSUnderlyingError=0x1702498a0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

这是创建目录的代码:

 do {
        try NSFileManager.defaultManager().createDirectoryAtPath(localURL.path!, withIntermediateDirectories: true, attributes: nil)
    } catch let error as NSError {
        NSLog("Unable to create directory \(error.debugDescription)")
    }


推荐答案

我认为这里的问题是 tmp 文件目录实际上不在 / tmp / Documents (例如,它看起来好像 / Documents 实际上 /用户/ Documents ,其实际上是 / private / var / mobile / Documents ,请参见: https://www.theiphonewiki.com/wiki/

I assume that the issue here is that the tmp and Documents directories don't actually live at /tmp and /Documents (for instance, it appears as though /Documents is actually /User/Documents, which is actually /private/var/mobile/Documents, see: https://www.theiphonewiki.com/wiki/)

您需要确保创建基于文件的URL关闭系统认为这些目录,而不是字符串:

You'll want to make sure you're creating your File URLs based off where the system thinks those directories are, rather than a string:

NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory()];
NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"my_file"] URLByAppendingPathExtension:@"txt"];

或类似的 NSDocumentDirectory 。至于为什么在模拟器上工作:我认为这是因为模拟器上的沙盒不像真实设备那样工作,而 / tmp 显然是您可以写的有效位置(尽管可能不是您想要写的两个),如果您尝试在真实设备上执行此操作,则iOS会抛出嘶嘶作用)。

Or similar for NSDocumentDirectory. As for why that works on the simulator: I assume this is because sandboxing on the simulator doesn't work the same way as a real device, and that /tmp is apparently a valid location you can write to (though likely not the one you want to be writing two, as evidenced by iOS throwing a hissy fit when you try to do it on a real device).

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

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