tonilopezmr / tonilopezmr.github.io

My web portfolio.
https://tonilopezmr-github-io.vercel.app
Other
4 stars 1 forks source link

Upload an Object in Amazon S3 with public access #24

Open tonilopezmr opened 6 years ago

tonilopezmr commented 6 years ago

You can use a PutObjectRequest to easily configure your PUT rest method.

Example code:

val put = PutObjectRequest(configuration.bucketName, uploadFileName, fileToUpload)
put.withCannedAcl(CannedAccessControlList.PublicRead)
amazonS3.putObject(put)

If you want to add some metadata to the HTTP Request then you can create a MetadataObject and add information like headers and content encoding, length, etc...

val objectMetadata = ObjectMetadata()
objectMetadata.setHeader("x-amz-acl", "public-read")

put.withMetadata(objectMetadata)

References

Bluemix Cloud Object Storage Amazon PUT object