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

Add x-amz-checksum headers on put_object #256

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/ex_aws/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -848,13 +848,21 @@ defmodule ExAws.S3 do
| {:if_unmodified_since, binary}
| {:if_match, binary}
| {:if_none_match, binary}
| {:x_amz_checksum_mode, binary}
@type head_object_opts :: [head_object_opt]

@doc "Determine if an object exists"
@spec head_object(bucket :: binary, object :: binary) :: ExAws.Operation.S3.t()
@spec head_object(bucket :: binary, object :: binary, opts :: head_object_opts) ::
ExAws.Operation.S3.t()
@request_headers [:range, :if_modified_since, :if_unmodified_since, :if_match, :if_none_match]
@request_headers [
:range,
:if_modified_since,
:if_unmodified_since,
:if_match,
:if_none_match,
:x_amz_checksum_mode
]
def head_object(bucket, object, opts \\ []) do
opts = opts |> Map.new()

Expand Down Expand Up @@ -939,7 +947,14 @@ defmodule ExAws.S3 do
@spec put_object(bucket :: binary, object :: binary, body :: binary, opts :: put_object_opts) ::
ExAws.Operation.S3.t()
def put_object(bucket, object, body, opts \\ []) do
request(:put, bucket, object, body: body, headers: put_object_headers(opts))
{ct, content_hash} = calculate_content_hash(body)

headers =
opts
|> put_object_headers()
|> Map.merge(%{ct => content_hash})

request(:put, bucket, object, body: body, headers: headers)
end

@doc "Create or update an object's access control policy"
Expand Down