简体   繁体   中英

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.

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:

在此处输入图像描述

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

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