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

Bug: s3 put_object_tagging #362

Closed
captchanjack opened this issue May 5, 2021 · 1 comment
Closed

Bug: s3 put_object_tagging #362

captchanjack opened this issue May 5, 2021 · 1 comment

Comments

@captchanjack
Copy link

The high level function put_object_tagging is calling the low level PUT function incorrectly.

It's forming the Tagging payload as part of the uri, when the S3 API is expecting it as XML in the body.

Here's what I did with the low level PUT function to get it working:

"""
	_tagging_payload(tags::AbstractDict)

Forms the PUT XML body for the S3 object tagging API.
"""
function _tagging_payload(tags::AbstractDict)
	payload = ""

	for (k, v) in tags
		payload *= """
		<Tag>
			<Key>$k</Key>
			<Value>$v</Value>
		</Tag>
		"""
	end

	return """
	<Tagging>
		<TagSet>
			$payload
		</TagSet>
	</Tagging>
	"""
end

"""
	put_object_tags(bucket, key, tags::AbstractDict)

Add or overwrites existing S3 object's tags.
"""
function put_object_tags(bucket, key, tags::AbstractDict; aws_config=global_aws_config())
	existings_tags = get_object_tags(bucket, key; aws_config=aws_config)
	merge!(existings_tags, tags)
	AWSServices.s3("PUT", "/$(bucket)/$(key)?tagging", Dict("body" => _tagging_payload(existings_tags)); aws_config=aws_config)
end
@mattBrzezinski
Copy link
Member

Same as #219

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

No branches or pull requests

2 participants