Skip to content

pause/resume/cancel upload #1249

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

Closed
huluyige opened this issue May 27, 2021 · 5 comments
Closed

pause/resume/cancel upload #1249

huluyige opened this issue May 27, 2021 · 5 comments
Labels
closing soon This issue will be closed in 7 days unless further comments are made. documentation Documentation improvements question General question storage Issues related to the Storage category

Comments

@huluyige
Copy link

huluyige commented May 27, 2021

Describe the bug
I can't find docs about pause/resume/cancel uploads

Hello I'am studying the storage plugin to test if i can pause/resume uploads like the old sdk, unfortunately I didn't find it. I just find a simple method:

        let dataString = "My Data"
        let fileNameKey = "myFile.txt"
        let filename = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
            .appendingPathComponent(fileNameKey)
        do {
            try dataString.write(to: filename, atomically: true, encoding: String.Encoding.utf8)
        } catch {
            print("Failed to write to file \(error)")
        }

        Amplify.Storage.uploadFile(
            key: fileNameKey,
            local: filename,
            progressListener: { progress in
                print("Progress: \(progress)")
            }, resultListener: { event in
                switch event {
                case let .success(data):
                    print("Completed: \(data)")
                case let .failure(storageError):
                    print("Failed: \(storageError.errorDescription). \(storageError.recoverySuggestion)")
                }
            }
        )

Could you please make it clear if the amplify sdk allows to do these? if yes, Could you provide some samples "?
Thank you !

@brennanMKE brennanMKE added follow up Requires follow up from maintainers question General question storage Issues related to the Storage category labels May 29, 2021
@lawmicha lawmicha added the documentation Documentation improvements label Jun 3, 2021
@lawmicha
Copy link
Contributor

lawmicha commented Jun 3, 2021

Hi @huluyige, thanks for bring this to our attention. Please take a look at https://github.com/aws-amplify/amplify-ios/blob/main/AmplifyPlugins/Storage/AWSS3StoragePluginFunctionalTests/ResumabilityTests/AWSS3StoragePluginGetDataResumabilityTests.swift and let us know if this works for you.

let operation = Amplify.Storage.downloadData(
            key: key,
            options: nil,
            progressListener: { progress in
           // progress.fractionCompleted 
        }, resultListener: { result in
            switch result {
            case .success:
                print("Success")
            case .failure(let error):
                print("Failed with \(error)")
            }
        })

// pause / resume / cancel
operation.pause()
operation.resume()
operation.cancel()

We'll take a follow up to improve the documentation at https://docs.amplify.aws/lib/storage/upload/q/platform/ios

@lawmicha
Copy link
Contributor

lawmicha commented Jun 4, 2021

related doc improvements aws-amplify/docs#3290

@huluyige
Copy link
Author

huluyige commented Jun 7, 2021

Hello @lawmicha thank you for reply. Is there a doc talking about resuming after app restart ? like something amplify.getTasks

@palpatim
Copy link
Member

Hi @huluyige,

Amplify doesn't currently support resuming background tasks after app restart. You can see a discussion here and the associated feature request.

@palpatim palpatim added closing soon This issue will be closed in 7 days unless further comments are made. and removed follow up Requires follow up from maintainers labels Jun 16, 2021
@github-actions
Copy link
Contributor

This issue is being automatically closed due to inactivity. If you believe it was closed by mistake, provide an update and re-open it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closing soon This issue will be closed in 7 days unless further comments are made. documentation Documentation improvements question General question storage Issues related to the Storage category
Projects
None yet
Development

No branches or pull requests

4 participants