Method: Aliyun::OSS::Protocol#create_bucket

Defined in:
lib/aliyun/oss/protocol.rb

#create_bucket(name, opts = {}) ⇒ Object

Create a bucket

Examples:

oss-cn-hangzhou

Parameters:

  • name (String)

    the bucket name

  • opts (Hash) (defaults to: {})

    options

Options Hash (opts):

  • :location (String)

    the region where the bucket is located



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/aliyun/oss/protocol.rb', line 98

def create_bucket(name, opts = {})
  logger.info("Begin create bucket, name: #{name}, opts: #{opts}")

  location = opts[:location]
  body = nil
  if location
    builder = Nokogiri::XML::Builder.new do |xml|
      xml.CreateBucketConfiguration {
        xml.LocationConstraint location
      }
    end
    body = builder.to_xml
  end

  @http.put({:bucket => name}, {:body => body})

  logger.info("Done create bucket")
end