Amazon Simple Storage Service
Developer Guide (API Version 2006-03-01)

Upload an Object Using a Presigned URL (AWS SDK for Ruby)

The following tasks guide you through using a Ruby script to upload an object using a presigned URL for SDK for Ruby - Version 3.

Uploading Objects - SDK for Ruby - Version 3


Create an instance of the Aws::S3::Resource class.


Provide a bucket name and an object key by calling the #bucket[] and the #object[] methods of your Aws::S3::Resource class instance.

Generate a presigned URL by creating an instance of the URI class, and use it to parse the .presigned_url method of your Aws::S3::Resource class instance. You must specify :put as an argument to .presigned_url, and you must specify PUT to Net::HTTP::Session#send_request if you want to upload an object.


Anyone with the presigned URL can upload an object.

The upload creates an object or replaces any existing object with the same key that is specified in the presigned URL.

The following Ruby code example demonstrates the preceding tasks for SDK for Ruby - Version 3.

#Uploading an object using a presigned URL for SDK for Ruby - Version 3. require 'aws-sdk-s3' require 'net/http' s3 ='us-west-2') obj = s3.bucket('BucketName').object('KeyName') # Replace BucketName with the name of your bucket. # Replace KeyName with the name of the object you are creating or replacing. url = URI.parse(obj.presigned_url(:put)) body = "Hello World!" # This is the contents of your object. In this case, it's a simple string. Net::HTTP.start( do |http| http.send_request("PUT", url.request_uri, body, { # This is required, or Net::HTTP will add a default unsigned content-type. "content-type" => "", }) end puts # This will print out the contents of your object to the terminal window.