【问题标题】:Body file is unreachable error when upload a file to firebase将文件上传到 Firebase 时,正文文件无法访问错误
【发布时间】:2017-06-17 18:33:33
【问题描述】:
NSString *filetotest=[NSString stringWithFormat:@"/var/mobile/Containers/Data/Application/3A203232-06BF-41CB-8456-1F2341C06934/Documents/"];
NSString *filessss=[NSString stringWithFormat:@"/var/mobile/Containers/Data/Application/3A203232-06BF-41CB-8456-1F2341C06934/Documents/100445.jpg"];

// File located on disk
NSURL *localFile = [NSURL URLWithString:filessss];

[@"100445.jpg" writeToFile:filetotest atomically:YES];


// Get a reference to the storage service using the default Firebase App
FIRStorage *storage = [FIRStorage storage];

// Create a storage reference from our storage service
FIRStorageReference *storageRef = [storage referenceForURL:@"gs://gnts-xxxxx.appspot.com"];

// Create a reference to the file you want to upload
FIRStorageReference *riversRef = [storageRef child:@"Test"];

// Upload the file to the path "images/rivers.jpg"
FIRStorageUploadTask *uploadTask = [riversRef putFile:localFile metadata:nil completion:^(FIRStorageMetadata *metadata, NSError *error) {
    if (error != nil) {
        // Uh-oh, an error occurred!
    } else {
        // Metadata contains file metadata such as size, content-type, and download URL.
        NSURL *downloadURL = metadata.downloadURL;
    }
}];

有错误

CFURLResourceIsReachable 失败,因为它传递了一个没有方案的 URL

无法访问正文文件:/var/mobile/Containers/Data/Application/3A203232-06BF-41CB-8456-1F2341C06934/Documents/100445.jpg Error Domain=NSCocoaErrorDomain Code=4 "该文件不存在。"

【问题讨论】:

  • 而不是 NSURL *localFile = [NSURL URLWithString:filessss]; ,使用 NSURL *localFile = [NSURL fileURLWithPath:filessss];

标签: ios objective-c nsfilemanager firebase-storage


【解决方案1】:

如果您从本地加载文件,请使用[NSURL fileURLWithPath:] 而不是[NSURL URLWithString:]

// File located on disk
NSURL *localFile = [NSURL fileURLWithPath:filessss];

【讨论】:

  • 得到错误无法获取文件大小:错误域=NSCocoaErrorDomain Code=260“文件“100445.jpg”无法打开,因为没有这样的文件。” UserInfo={NSURL=file:///var/mobile/Containers/Data/Application/3A203232-06BF-41CB-8456-1F2341C06934/Documents/100445.jpg, NSFilePath=/var/mobile/Containers/Data/Application/3A203232 -06BF-41CB-8456-1F2341C06934/Documents/100445.jpg, NSUnderlyingError=0x168b63d0 {错误域=NSPOSIXErrorDomain Code=2“没有这样的文件或目录”}} /var/mobile/Containers/Data/Application/3A203232-06BF- 41CB-8456-1F2341C06934/Documents/100445.jpg
  • 您确定该文件存在于 Path 中吗?
【解决方案2】:

不,我得到了这个代码每次都改变的路径,

NSString *documentsPath= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

1。 文档路径 /var/mobile/Containers/Data/Application/7D71C4C4-33F8-4D70-AF1E-AFDEB4634031/Documents

2。 filesPath /var/mobile/Containers/Data/Application/B47C0C4B-0FA1-4E85-9573-89F2D6389535/Documents

我静态使用这个文件路径,这会导致这个错误。 现在我的问题通过直接应用文件路径解决了, 谢谢大家。

【讨论】:

    猜你喜欢
    • 2019-03-15
    • 1970-01-01
    • 2019-11-06
    • 2017-11-07
    • 2021-12-05
    • 2017-06-09
    • 2021-09-19
    • 2022-11-03
    • 1970-01-01
    相关资源
    最近更新 更多