Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions FirebaseStorage/Sources/FIRStorageReference.m
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ - (FIRStorageUploadTask *)putFile:(NSURL *)fileURL
- (FIRStorageUploadTask *)putFile:(NSURL *)fileURL
metadata:(nullable FIRStorageMetadata *)metadata
completion:(nullable FIRStorageVoidMetadataError)completion {
if ([fileURL frs_hasDirectoryPath]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check that it is a file versus not a directory? Like https://github.com/firebase/firebase-ios-sdk/pull/5742/files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will play with this. Maybe instead of the check looking like this:

 if fileUrl is a directory -> return error

We could instead have something like?:

 if !(fileUrl is a file) -> return error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I think the 2nd option is preferable because there may be other types of URLs that are not handled now, e.g. a symlink or not a file system URL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

NSError *error = [FIRStorageErrors
errorWithCustomMessage:
@"Failed to recognize file for file URL. Ensure file URL is not a directory."];
completion(nil, error);
}

if (!metadata) {
metadata = [[FIRStorageMetadata alloc] init];
}
Expand Down
10 changes: 10 additions & 0 deletions FirebaseStorage/Sources/FIRStorageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,14 @@ NS_ASSUME_NONNULL_BEGIN

@end

@interface NSURL (FIRStorageNSURLHelpers)

/**
* Returns a boolean indicating that the NSURL instance represents a file directory
* @return True if the NSURL object represents a file directory, and false if otherwise
*/
- (BOOL)frs_hasDirectoryPath;

@end

NS_ASSUME_NONNULL_END
15 changes: 15 additions & 0 deletions FirebaseStorage/Sources/FIRStorageUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,18 @@ + (nullable instancetype)frs_dataFromJSONDictionary:(nullable NSDictionary *)dic
}

@end

@implementation NSURL (FIRStorageNSURLHelpers)

- (BOOL)frs_hasDirectoryPath {
if (@available(macOS 10.11, iOS 9.0, watchOS 2.0, tvOS 9.0, *)) {
return [self hasDirectoryPath];
} else {
NSError *error;
NSNumber *isDirectory = [NSNumber numberWithBool:NO];
[self getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error];
return [isDirectory boolValue];
}
}

@end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>Template: 08_Home_Improvement (2014-07-09 16:51)</string>
<string>G-r8-1GP146</string>
</array>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
58239D62-15E4-43C7-A38A-62E3F530B363
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 3 additions & 1 deletion FirebaseStorageSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas
int_tests.requires_app_host = true
# Resources are shared with FirebaseStorage's integration tests.
int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat',
'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist'
'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist',
'FirebaseStorage/Tests/Integration/Resources/Home Improvement.numbers',
'FirebaseStorage/Tests/Integration/Resources/star_wars.pdf'
int_tests.dependency 'FirebaseAuth', '~> 6.5'
end
end
35 changes: 35 additions & 0 deletions FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ class StorageIntegration: XCTestCase {
waitForExpectations()
}

func testSimplePutCustomFile() throws {
let expectation = self.expectation(description: #function)
let fileName = "star_wars.pdf"
let bundle = Bundle(for: StorageIntegration.self)
let filePath = try XCTUnwrap(bundle.path(forResource: fileName, ofType: ""),
"Failed to get filePath")
let ref = storage.reference(withPath: "ios/public/" + fileName)
ref.putFile(from: URL(fileURLWithPath: filePath)) { result in
self.assertResultSuccess(result)
expectation.fulfill()
}
waitForExpectations()
}

func testSimplePutFile() throws {
let expectation = self.expectation(description: #function)
let putFileExpectation = self.expectation(description: "putFile")
Expand Down Expand Up @@ -256,6 +270,27 @@ class StorageIntegration: XCTestCase {
waitForExpectations()
}

func testAttemptToUploadDirectory() throws {
let expectation = self.expectation(description: #function)

let fileName = "Home Improvement.numbers"
let bundle = Bundle(for: StorageIntegration.self)
let fileURL = try XCTUnwrap(bundle.url(forResource: fileName, withExtension: ""),
"Failed to get filePath")
let ref = storage.reference(withPath: "ios/public/" + fileName)
ref.putFile(from: fileURL) { result in
switch result {
case let .success(metadata):
XCTAssertNil(metadata)
XCTFail("This test should have thrown an error.")
case let .failure(error):
XCTAssertNotNil(error)
expectation.fulfill()
}
}
waitForExpectations()
}

func testPutFileWithSpecialCharacters() throws {
let expectation = self.expectation(description: #function)

Expand Down