aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

S3 Presign Head method

Open bartekbluestone opened this issue 1 year ago • 9 comments

Describe the feature

Now there is possibility to presign url for get/post/put/delete but I miss HEAD method. It is also possible using v1 sdk.

Use Case

Generate presign url to s3 object for HEAD method.

Proposed Solution

No response

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS Java SDK version used

2.24.7

JDK version used

17

Operating System and version

docker and amazon corretto 17

bartekbluestone avatar Jun 10 '24 14:06 bartekbluestone

@bartekbluestone can you tell us more about your use case?

How would you use the presigned head request?

debora-ito avatar Jun 11 '24 21:06 debora-ito

Hi! In our app we generate urls for our clients. On of methods that they requested is HEAD and we added it few months ago, but in meantime we updated app and its dependecies, and also migrated aws sdk 1 to aws sdk 2. Previous sdk allowed us to prepare such presign url for head, and as I checked, go sdk also allow to create such request.

bartekbluestone avatar Jun 12 '24 07:06 bartekbluestone

My use case is I want to generate a head request and a get request for downloading an object from s3. the client makes a head request to poll until the file to download is actually available.

It would be nicer if S3 just let me do a HEAD request on a presigned GET url (which from my reading of the HTTP spec... it should). But since the http method is included in the signature, making a HEAD request to a GET url will return a 403.

The absence of this functionality is a bit of a blocker to migrating to the v2 SDK from V1, since the V1 SDK supports creating these urls.

tmccombs avatar Aug 06 '24 21:08 tmccombs

Thank you for all the inputs. We've added this to our backlog.

debora-ito avatar Aug 13 '24 01:08 debora-ito

For my use case it would also be nice if I could use a GetObjectRequest to generate the signed HEAD url, either directly, or by having some way to convert a GetObjectRequest to a HeadObjectRequest.

tmccombs avatar Oct 24 '24 21:10 tmccombs

For my use case, we are using chunk download and need to use the HEAD request to get the content length of the file.

mcheung610 avatar Apr 24 '25 01:04 mcheung610

+1

100tomer avatar Apr 28 '25 13:04 100tomer

Also adding a +1 here - would be really helpful for us

jjank avatar May 12 '25 12:05 jjank

Yes. Please. This is stopping us from migrating to v2.

marchenault avatar May 15 '25 21:05 marchenault

Presigned HeadObject and HeadBucket requests are now supported, released in version 2.31.66.

Usage Example:

S3Presigner presigner = S3Presigner.create();

PresignedHeadObjectRequest presigned =
            presigner.presignHeadObject(r -> r.signatureDuration(Duration.ofMinutes(30))
                                             .headObjectRequest(hor -> hor
                                                                         .bucket(testBucket)
                                                                         .key(testGetObjectKey)));

SdkHttpClient httpClient = ApacheHttpClient.builder().build(); // or UrlConnectionHttpClient.builder().build()

HttpExecuteRequest request = HttpExecuteRequest.builder()
                                             .request(presigned.httpRequest())
                                             .build();

HttpExecuteResponse response = httpClient.prepareRequest(request).call();
String contentLength = response.httpResponse().firstMatchingHeader("Content-Length").orElse("0");

debora-ito avatar Jun 25 '25 00:06 debora-ito

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Jun 25 '25 00:06 github-actions[bot]