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

blob/s3blob: url encode CopySource #3402

Closed
srerickson opened this issue Mar 13, 2024 · 0 comments · Fixed by #3403
Closed

blob/s3blob: url encode CopySource #3402

srerickson opened this issue Mar 13, 2024 · 0 comments · Fixed by #3403

Comments

@srerickson
Copy link

Describe the bug

For s3 buckets, Copy() returns NoSuchKey: The specified key does not exist if the object source key includes the url path escape sequence %2f. See the example below, which uses the source key test/example%2fkey.

I think the problem is that CopyObjectInput.CopySource is supposed to be URL encoded.

To Reproduce

package main

import (
	"context"
	"log"
	"net/url"

	"gocloud.dev/blob"
	_ "gocloud.dev/blob/s3blob"
)

func main() {
	var (
		ctx  = context.Background()
		key  = "test/example%2fkey"
		dst  = "test/copy"
		byts = []byte("testing")
	)
	bucket, err := blob.OpenBucket(ctx, "s3://yourtestbucket?region=us-west-2&awssdk=v2")
	if err != nil {
		log.Fatal(err)
	}
	defer bucket.Close()
	if err := bucket.WriteAll(ctx, key, byts, nil); err != nil {
		log.Fatal(err)
	}

	// works if source key is url-encoded
	if err := bucket.Copy(ctx, dst, url.PathEscape(key), nil); err != nil {
		log.Fatalf("with url encoded source: %v\n", err)
	}

	// but this fails with error: `NoSuchKey: The specified key does not exist`
	if err := bucket.Copy(ctx, dst, key, nil); err != nil {
		log.Fatalf("without url encoded source: %v\n", err)
	}
}

Expected behavior

If an object key works with WriteAll(), I expect it to work withCopy()

Version

go.mod:

go 1.22.1

require gocloud.dev v0.37.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant