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

AWSS3TransferUtility GIF fails without any response #5462

Open
nastasiupta opened this issue Nov 13, 2024 · 2 comments
Open

AWSS3TransferUtility GIF fails without any response #5462

nastasiupta opened this issue Nov 13, 2024 · 2 comments
Labels
closing soon pending-community-response Issue is pending response from the issue requestor question General question s3 Issues related to S3

Comments

@nastasiupta
Copy link

nastasiupta commented Nov 13, 2024

Describe the bug
I have a function that uses awsTransferUtility to upload from an URL (for example a video or a gif)

To Reproduce

  1. The user selects a GIF from Photos app
  2. Setup AWSS3TransferUtility and upload the file from given URL:
return try await withCheckedThrowingContinuation { continuation in
    defer {
        let continuationError = NSError(domain: "S3AsyncWorker",
                                        code: 999,
                                        userInfo: [NSLocalizedDescriptionKey: "Continuation was not resumed properly."])
            continuation.resume(throwing: continuationError)
    }

    func transferUtility(uploadFile: URL, contentType: String) {
        awsTransferUtility.uploadFile(uploadFile,
                                      bucket: bucket,
                                      key: key,
                                      contentType: contentType,
                                      expression: expression) { task, error in
            if let error = error {
                ....
            } else {
               ....
            }
        }
    }
    
    ....
}
  1. The completion block is not called
    The same flow is executed for a video and everything works great, in case of video contentType is "video/mp4", in case of gif is "image/gif"
    This is printed at console: SWIFT TASK CONTINUATION MISUSE: execute(data:) leaked its continuation!
    Later edit:
    after I added defer, the worker is throwing the error "Continuation was not resumed properly."

Environment(please complete the following information):

  • SDK Version: 2.37.2
  • Dependency Manager: SPM
  • Xcode Version: 16.1

Device Information (please complete the following information):

  • Device: iPhone 14 Pro
  • iOS Version: 18.1

Later edit:
So, the issue is related to the url for GIFs selected from Photos app.
At the moment when the user selects a GIF, I covert it to Data and use awsTransferUtility.uploadData and everything works as expected.

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Nov 13, 2024
@edisooon edisooon self-assigned this Nov 14, 2024
@edisooon edisooon added s3 Issues related to S3 question General question and removed pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Nov 14, 2024
@edisooon
Copy link
Member

Hi @nastasiupta, thank you for submitting the issue!
One of our team members will look into this and verify if it's a bug in the library.
Meanwhile, could you provide us with your full logs?

@edisooon edisooon removed their assignment Nov 18, 2024
@sebaland
Copy link
Member

sebaland commented Jan 3, 2025

Hi @nastasiupta, sorry for the delay in our response.
I was able to reproduce this situation in which the completionHandler is not invoked, and as such you get those "SWIFT TASK CONTINUATION MISUSE: execute(data:) leaked its continuation" messages.

This is happening because the completionHandler is only invoked then the actual upload task completes, either with success or with error. But the TransferUtility also performs some validations before attempting to upload, and if any of those fail then the upload won't even be attempted. In these situations, the completionHandler is not invoked, as no upload task was created.

I recognize that this is a confusing and somewhat unintuitive behaviour, but all the uploadFile APIs actually return a AWSTask object which will have its error property populated on these situations.

In your code, you could handle it like this:

let uploadTask = awsTransferUtility.uploadFile(
    uploadFile,
    bucket: bucket,
    key: key,
    contentType: contentType,
    expression: expression
) { task, error in
    if let error = error {
        // Upload failed, resume continuation with error
        continuation.resume(throwing: error)
    } else {
        // Upload succeeded, resume continuation
        continuation.resume()
    }
}

if let error = uploadTask.error {
    // Upload was not even attempted, resume continuation with error
    continuation.resume(throwing: error)
}

@sebaland sebaland added pending-community-response Issue is pending response from the issue requestor closing soon labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing soon pending-community-response Issue is pending response from the issue requestor question General question s3 Issues related to S3
Projects
None yet
Development

No branches or pull requests

3 participants