Skip to content

Commit

Permalink
Merge pull request #19 from ky-is/fix-storage-metadata
Browse files Browse the repository at this point in the history
Add storage URL helpers and fix metadata error
  • Loading branch information
marcprux authored Dec 13, 2024
2 parents 6fb5a73 + 40b3f91 commit 9b3a3fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/SkipFirebaseStorage/SkipFirebaseStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public final class Storage {
Storage(com.google.firebase.storage.FirebaseStorage.getInstance(app.app))
}

public static func storage(url: String) -> Storage {
Storage(com.google.firebase.storage.FirebaseStorage.getInstance(url))
}

public static func storage(app: FirebaseApp, url: String) -> Storage {
Storage(com.google.firebase.storage.FirebaseStorage.getInstance(app.app, url))
}

public var app: FirebaseApp {
FirebaseApp(app: platformValue.getApp())
}
Expand Down Expand Up @@ -238,7 +246,7 @@ public class StorageReference: KotlinConverting<com.google.firebase.storage.Stor
public func putFile(from fileURL: URL, metadata: StorageMetadata? = nil, completion: (_: StorageMetadata?, _: Error?) -> Void = { _, _ in }) -> StorageUploadTask {
let fileURI: android.net.Uri = android.net.Uri.parse(fileURL.kotlin().toString())

let uploadTask = platformValue.putFile(fileURI, metadata?.platformValue, nil)
let uploadTask = metadata == nil ? platformValue.putFile(fileURI) : platformValue.putFile(fileURI, metadata!.platformValue, nil)
uploadTask.addOnFailureListener { exception in
completion(nil, ErrorException(exception))
}.addOnSuccessListener { taskSnapshot in
Expand Down
2 changes: 2 additions & 0 deletions Tests/SkipFirebaseStorageTests/SkipFirebaseStorageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ let logger: Logger = Logger(subsystem: "SkipFirebaseStorageTests", category: "Te
let fileURL = URL(fileURLWithPath: "/dev/null")

// we don't actually connect to the storage here, so we are just checking the API signatures for get/put data
let storageCustomURL = Storage.storage(url: "gs://")

let storage = Storage.storage()
let ref: StorageReference = storage.reference()
let _: StorageReference = storage.reference(withPath: "test")
Expand Down

0 comments on commit 9b3a3fb

Please sign in to comment.