Skip to content

Commit 3f9fc90

Browse files
committed
[Storage] Improve how GetFile handles paths
1 parent 4086d40 commit 3f9fc90

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

release_build_files/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ workflow use only during the development of your app, not for publicly shipping
613613
code.
614614

615615
## Release Notes
616+
### Upcoming
617+
- Changes
618+
- Storage (iOS): Handle absolute paths being provided to GetFile. (#1724)
619+
616620
### 13.0.0
617621
- Changes
618622
- General (Android): Update to Firebase Android BoM version 34.0.0.

storage/integration_test/src/integration_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ TEST_F(FirebaseStorageTest, TestPutFileAndGetFile) {
647647
std::string path = PathForResource() + kGetFileTestFile;
648648
// Cloud Storage expects a URI, so add file:// in front of local
649649
// paths.
650-
std::string file_path = kFileUriScheme + path;
650+
// TODO: Revert, just testing to see if this will pass without.
651+
std::string file_path = /*kFileUriScheme +*/ path;
651652

652653
LogDebug("Saving to local file: %s", path.c_str());
653654

storage/src/ios/storage_reference_ios.mm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,21 @@
142142
// Cache a copy of the impl and storage, in case this is destroyed before the thread runs.
143143
FIRStorageReference* my_impl = impl();
144144
StorageInternal* storage = storage_;
145-
NSURL* local_file_url = [NSURL URLWithString:@(path)];
145+
NSString* path_string = @(path);
146+
NSURL* local_file_url = nil;
147+
if ([path_string hasPrefix:@"file://"]) {
148+
// If it starts with the prefix, load it assuming a URL string.
149+
local_file_url = [NSURL URLWithString:path_string];
150+
} else {
151+
// Otherwise, assume it is a file path.
152+
local_file_url = [NSURL fileURLWithPath:path_string];
153+
}
154+
// If we still failed to convert the path, error out.
155+
if (local_file_url == nil) {
156+
future_impl->Complete(handle, kErrorUnknown,
157+
"Unable to convert provided path to valid URL");
158+
return GetFileLastResult();
159+
}
146160
util::DispatchAsyncSafeMainQueue(^() {
147161
FIRStorageDownloadTask *download_task;
148162
{

0 commit comments

Comments
 (0)