【发布时间】: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