Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage - new 'putFile' method implementation breaks old code #10353

Closed
alexmomotiuk opened this issue Oct 14, 2022 · 10 comments · Fixed by #10356
Closed

Storage - new 'putFile' method implementation breaks old code #10353

alexmomotiuk opened this issue Oct 14, 2022 · 10 comments · Fixed by #10356

Comments

@alexmomotiuk
Copy link

Description

The new implementation of 'putFile' method, breaks old code.
If I pass StorageMetadata object with set up 'contentType' to this method, I get crash with error

FirebaseStorage/StorageUploadTask.swift:68: Fatal error: Internal error enqueueing a Storage task

because 'path' and 'name' won't be set for metadata object from parameters.

  open func putFile(from fileURL: URL,
                    metadata: StorageMetadata? = nil,
                    completion: ((_: StorageMetadata?, _: Error?) -> Void)?) -> StorageUploadTask {
    var putMetadata: StorageMetadata
    if metadata == nil {
      putMetadata = StorageMetadata()
      if let path = path.object {
        putMetadata.path = path
        putMetadata.name = (path as NSString).lastPathComponent as String
      }
    } else {
      putMetadata = metadata!
    }

'putData' method has different implementation and works well.

open func putData(_ uploadData: Data,
                    metadata: StorageMetadata? = nil,
                    completion: ((_: StorageMetadata?, _: Error?) -> Void)?) -> StorageUploadTask {
    let putMetadata = metadata ?? StorageMetadata()
    if let path = path.object {
      putMetadata.path = path
      putMetadata.name = (path as NSString).lastPathComponent as String
    }

Reproducing the issue

No response

Firebase SDK Version

10

Xcode Version

14.0.1

Installation Method

CocoaPods

Firebase Product(s)

Storage

Targeted Platforms

iOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

No response

If using CocoaPods, the project's Podfile.lock

No response

@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@maneesht
Copy link
Contributor

@alexmomotiuk - thank you for looking into this issue and reporting it. I have merged the PR and the fix should be in the next release. In the meantime, if you initialize the metadata before passing it to the putFile function, you should be able to bypass the error.

@morganchen12 morganchen12 added this to the 10.1.0 - M123 milestone Oct 14, 2022
@jtressle
Copy link

@maneesht how do we fix this issue while we wait for the next release?

@alexmomotiuk
Copy link
Author

alexmomotiuk commented Oct 18, 2022

@jtressle don't pass metadata, or roll back to a previous version of firebase

@jtressle
Copy link

jtressle commented Oct 18, 2022

@alexmomotiuk I require the metadata so I ended up using the putData method you mentioned.

@maneesht
Copy link
Contributor

@jtressle - if you fill the metadata with the proper path and name properties before you pass it to putFile, you shouldn't have any issues.
Please see https://github.com/firebase/firebase-ios-sdk/pull/10356/files#diff-8a6fda4f1d223479d5cafa7db5c6ca8f33220cbb93e59e0e3352c23eb8f7e4aeR215

@jtressle
Copy link

@maneesht can you provide an example?

I'm getting the error Cannot assign to property: 'name' setter is inaccessible for both the metadata name and path. This is how I'm setting the variables. Ref is my document reference.

let metadata = StorageMetadata() metadata.name = (ref.fullPath as NSString).lastPathComponent as String metadata.path = ref.fullPath

Thanks.

@maneesht
Copy link
Contributor

@jtressle - I was mistaken. name and path are internal only. Please wait until the next release or roll back to a previous version. The next release should be out soon.

@mikehardy
Copy link
Contributor

it is possible to make an NSMutableDictionary (alloc + init it), put a "name" entry in there that is the full path, then do initWithDictionary on the FIRStorageMetadata. The name gets copied to path and it all works. Of course that is internal stuff and a workaround and not supported and you accept responsibility etc ;-) just thought I would mention it

@maneesht
Copy link
Contributor

Thanks, @mikehardy!

@firebase firebase locked and limited conversation to collaborators Nov 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
7 participants