From 51e74aacc5884d464112c094868a9e81c0b6ff8f Mon Sep 17 00:00:00 2001 From: mlec <42201667+mlec1@users.noreply.github.com> Date: Fri, 19 Dec 2025 00:19:37 +0100 Subject: [PATCH] feat: add a warning in case the object doesn't exists before generating the presign url --- pkg/storage/sos/object.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/storage/sos/object.go b/pkg/storage/sos/object.go index 068888fe..cc4033f4 100644 --- a/pkg/storage/sos/object.go +++ b/pkg/storage/sos/object.go @@ -20,6 +20,7 @@ import ( s3manager "github.com/aws/aws-sdk-go-v2/feature/s3/manager" "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/aws/aws-sdk-go-v2/service/s3/types" + "github.com/aws/smithy-go" "github.com/dustin/go-humanize" "github.com/hashicorp/go-multierror" "github.com/vbauerster/mpb/v4" @@ -158,6 +159,19 @@ func (c *Client) GenPresignedURL(ctx context.Context, method, bucket, key string switch method { case "get": + // Check if the object exists + if _, err := c.S3Client.(*s3.Client).HeadObject(ctx, &s3.HeadObjectInput{ + Bucket: aws.String(bucket), + Key: aws.String(key), + }); err != nil { + var apiErr smithy.APIError + if errors.As(err, &apiErr) { + if apiErr.ErrorCode() == "NotFound" { + fmt.Printf("⚠️ The object %s/%s does not exist. The Presigned URL will return 404 ⚠️\n\n", bucket, key) + } + } + } + psURL, err = psClient.PresignGetObject(ctx, &s3.GetObjectInput{ Bucket: aws.String(bucket), Key: aws.String(key),