uddeshya pratik
uddeshya pratik

Reputation: 81

Uploading an Item with Metadata to an Amazon S3 Bucket using aws cli

I want to perform the same operation as below:

https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/s3-example-upload-bucket-item-with-metadata.html

require 'aws-sdk-s3'  # v2: require 'aws-sdk'
      
s3 = Aws::S3::Resource.new(region: 'us-west-2')

file = 'C:\file.txt'
bucket = 'my-bucket'
      
# Get just the file name
name = File.basename(file)

# Create the object to upload
obj = s3.bucket(bucket).object(name)

# Metadata to add
metadata = {"answer" => "42"}

# Upload it      
obj.upload_file(file, metadata: metadata)

But getting error message in aws cli

C:\Users\upratik>aws s3 cp "C:\Amedments\sharepoint.docx" s3://pubmgmt-poc/ --metadata = '{"answer" => "42"}'

Unknown options: '{answer,=

Any help will be appricated on this.

Upvotes: 2

Views: 3929

Answers (1)

Marcin
Marcin

Reputation: 238209

Usually you add --metadata to aws s3 cp as follows:

--metadata="answer=42" 

This will add user-defined metadata to the object uploaded which starts with x-amz-meta:

When you upload objects using the REST API, the optional user-defined metadata names must begin with "x-amz-meta-" to distinguish them from other HTTP headers

For example:

enter image description here

I tested this on Linux, but don't see a reason why it would be different on Windows.

Upvotes: 4

Related Questions