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

Unable to get presigned URL for UploadPart with all mandatory query parameters #1808

Closed
plu opened this issue Oct 30, 2024 · 2 comments · May be fixed by #1809
Closed

Unable to get presigned URL for UploadPart with all mandatory query parameters #1808

plu opened this issue Oct 30, 2024 · 2 comments · May be fixed by #1809
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@plu
Copy link

plu commented Oct 30, 2024

Describe the bug

I've tried to use two different API's to presign some UploadPart:

  • UploadPartInput.presign(config:expiration:)
  • S3Client.presignedRequestForUploadPart(input:expiration:)

Both API's return an incomplete URL. It does not contain all mandatory query parameters to successfully perform a multipart upload.

Expected Behavior

There should be an API in the SDK that returns a presigned URL with all mandatory parameters necessary to successfully perform a multipart upload on that URL.

Current Behavior

2024-10-30T08:11:18+0100 info URLSessionHTTPClient : [Logging] start URLRequest(https://bucketname.s3.eu-central-1.amazonaws.com/foo.txt?uploads) called
2024-10-30T08:11:18+0100 info URLSessionHTTPClient : [Logging]   body is Data
2024-10-30T08:11:18+0100 info URLSessionHTTPClient : [Logging] Either TLSOptions not set or missing values! Using default trust store.
2024-10-30T08:11:18+0100 info S3Client : [Logging] No checksum provided! Skipping flexible checksums workflow...
"Example 1 URL: Optional(https://bucketname.s3.eu-central-1.amazonaws.com/foo.txt?x-id=UploadPart&partNumber=1&uploadId=3apTN5sv8ATm2EM7Q6je1xahbvz1MbdJTYkzg4r.8.qS1gvtAjkmwi2RrtMbvCRYWU40kVyXgq1vMPSeQoUnqRrKvqNRXrJHe7sxibiSip1bG9DukQrOPa32O_Si2n3C)"
2024-10-30T08:11:18+0100 info S3Client : [Logging] No checksum provided! Skipping flexible checksums workflow...
"Example 2 URL: Optional(https://bucketname.s3.eu-central-1.amazonaws.com/foo.txt?x-id=UploadPart&partNumber=1&uploadId=3apTN5sv8ATm2EM7Q6je1xahbvz1MbdJTYkzg4r.8.qS1gvtAjkmwi2RrtMbvCRYWU40kVyXgq1vMPSeQoUnqRrKvqNRXrJHe7sxibiSip1bG9DukQrOPa32O_Si2n3C)"
Program ended with exit code: 0

Reproduction Steps

import AWSS3

@main
struct Example {
    static func main() async throws {
        let bucket = "bucketname"
        let configuration = try await S3Client.S3ClientConfiguration()
        let client = S3Client(config: configuration)

        let multipartUpload = try await client.createMultipartUpload(
            input: .init(
                bucket: bucket,
                key: "foo.txt"
            )
        )
        guard let uploadId = multipartUpload.uploadId else {
            preconditionFailure()
        }

        let uploadPartInput = UploadPartInput(
            bucket: bucket,
            key: "foo.txt",
            partNumber: 1,
            uploadId: uploadId
        )

        // Example 1
        try await {
            let request = try await uploadPartInput.presign(
                config: configuration,
                expiration: 1
            )

            debugPrint("Example 1 URL: \(request?.endpoint.url)")
        }()

        // Example 2
        try await {
            let request = try await client.presignedRequestForUploadPart(
                input: uploadPartInput,
                expiration: 1
            )

            debugPrint("Example 2 URL: \(request.url)")
        }()
    }
}

Possible Solution

Solution 1

  • UploadPartInput.presign(config:expiration:)
  • S3Client.presignedRequestForUploadPart(input:expiration:)

Both API's mentioned above return a URL that contains all mandatory query parameters to successfully upload a file.

Solution 2 (preferred)

Implement new API:

  • UploadPartInput.presignURL(config:expiration:)

This returns a URL that contains all mandatory query parameters to successfully upload a file.

Analogue to:

  • GetObjectInput.presignURL(config:expiration:)
  • PutObjectInput.presignURL(config:expiration:)

Additional Information/Context

When I try the presignURL API of PutObjectInput or GetObjectInput, I get a valid URL.

@main
struct Example {
    static func main() async throws {
        let bucket = "bucketname"
        let configuration = try await S3Client.S3ClientConfiguration()
        let client = S3Client(config: configuration)

        // Example 1
        try await {
            let input = GetObjectInput(bucket: bucket, key: "foo.txt")
            let url = try await input.presignURL(
                config: configuration,
                expiration: 1
            )
            debugPrint("Example 1 URL: \(url)")
        }()

        // Example 2
        try await {
            let input = PutObjectInput(bucket: bucket, key: "foo.txt")
            let url = try await input.presignURL(
                config: configuration,
                expiration: 1
            )
            debugPrint("Example 2 URL: \(url)")
        }()
    }
}

Output:

"Example 1 URL: Optional(https://bucketname.s3.eu-central-1.amazonaws.com/foo.txt?Bucket=bucketname&Key=foo.txt&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAXN62E7GOEXPZNANL%2F20241030%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20241030T072027Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1&X-Amz-Signature=7cea6cd8655530775273994dc0df92b923836062123a95039bf3b778578f7dfd)"
2024-10-30T08:20:27+0100 info S3Client : [Logging] No checksum provided! Skipping flexible checksums workflow...
"Example 2 URL: Optional(https://bucketname.s3.eu-central-1.amazonaws.com/foo.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAXN62E7GOEXPZNANL%2F20241030%2Feu-central-1%2Fs3%2Faws4_request&X-Amz-Date=20241030T072027Z&X-Amz-SignedHeaders=host&X-Amz-Expires=1&X-Amz-Signature=0ddef0a494855933ce2e9d0423bfe50db0a4af9f28f0770cadb610abbeb2ace6)"

AWS SWIFT SDK version used

1.0.29

Compiler and Version used

Xcode 15.4 + included Swift Version/Tools

Operating System and version

macOS 14.7

@plu plu added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 30, 2024
@plu
Copy link
Author

plu commented Oct 30, 2024

Sorry for opening a duplicate (#723). Is there any technical reason this cannot be implemented? I'd be happy to open a PR, if somebody gives me a starting point, please :).

@plu
Copy link
Author

plu commented Oct 31, 2024

Closing as duplicate of #723

@plu plu closed this as completed Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant