简体   繁体   中英

How do I do a HEAD operation on an AWS Presigned URL?

I am trying to get the size of an obejct in S3. I know I can do it via GET but I want to use the HEAD method. But I can't find in the AWS SDK HeadObjectPresignRequest only GetObjectPresignRequest . Using HEAD on the presigned URL gives me a 403

Right now what I am doing is Cancelling the fetch request

We need to pass headObject to getSignedUrl method itself.

JavaScript:

s3.getSignedUrl(
  "headObject",
  {
    Bucket: "my-test-bucket",
    Key: "path/to/my/object",
  },
  (error, url) => {
    if (error) console.log("error", error);
    if (url) console.log("url", url);
  }
);

Java:

AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion("us-east-1").build();       
URL url = s3Client.generatePresignedUrl(new GeneratePresignedUrlRequest("my-test-bucket", "path/to/my/object",HttpMethod.HEAD));
System.out.println(url.toString());     

Then HEAD request on the object.

curl --location --head 'https://my-test-bucket.s3.amazonaws.com/myobject?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA....Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210418T230000Z&X-Amz-Expires=900&X-Amz-Security-Token=....%2B31dbfIXMQ%3D%3D&X-Amz-Signature=...ad&X-Amz-SignedHeaders=host'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM