Aliyun.Oss.Bucket (aliyun_oss v2.0.0)
Bucket operations - basic operations.
Other operations can be found in:
Aliyun.Oss.Bucket.WORM
Aliyun.Oss.Bucket.ACL
Aliyun.Oss.Bucket.Lifecycle
Aliyun.Oss.Bucket.Versioning
Aliyun.Oss.Bucket.Replication
Aliyun.Oss.Bucket.Policy
Aliyun.Oss.Bucket.Inventory
Aliyun.Oss.Bucket.Logging
Aliyun.Oss.Bucket.Website
Aliyun.Oss.Bucket.Referer
Aliyun.Oss.Bucket.Tags
Aliyun.Oss.Bucket.Encryption
Aliyun.Oss.Bucket.RequestPayment
Aliyun.Oss.Bucket.CORS
Link to this section Summary
Functions
DeleteBucket - deletes a bucket.
GetBucket (ListObjects) - lists the information about all objects in a bucket.
GetBucketInfo - gets the information about a bucket.
GetBucketLocation - views the location information of a bucket.
ListBuckets - lists the information about all buckets.
GetBucketV2 (ListObjectsV2) - lists the information about all objects in a bucket.
Link to this section Types
error()
Link to this section Functions
delete_bucket(config, bucket, sub_resources \\ %{})
@spec delete_bucket(Aliyun.Oss.Config.t(), String.t(), map()) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}
DeleteBucket - deletes a bucket.
examples
Examples
iex> Aliyun.Oss.Bucket.delete_bucket(config, "some-bucket")
{:ok,
%Aliyun.Oss.Client.Response{
data: "",
headers: [
{"Server", "AliyunOSS"},
{"Date", "Fri, 11 Jan 2019 05:26:36 GMT"},
{"Content-Length", "0"},
{"Connection", "keep-alive"},
{"x-oss-request-id", "5C38290C41F2DE32412A3A88"},
{"x-oss-server-time", "230"}
]
}}
iex> Aliyun.Oss.Bucket.delete_bucket(config, "unknown-bucket")
{:error,
%Aliyun.Oss.Client.Error{
body: "<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist.</Message>
<RequestId>5C3829B29BF380354CF9C2E8</RequestId>
<HostId>unknown-bucket.oss-cn-shenzhen.aliyuncs.com</HostId>
<BucketName>unknown-bucket</BucketName>
</Error>",
parsed_details: %{
"BucketName" => "unknown-bucket",
"Code" => "NoSuchBucket",
"HostId" => "unknown-bucket.oss-cn-shenzhen.aliyuncs.com",
"Message" => "The specified bucket does not exist.",
"RequestId" => "5C3000000000000000000000"
},
status_code: 404
}}
get_bucket(config, bucket, query_params \\ %{}, sub_resources \\ %{})
@spec get_bucket(Aliyun.Oss.Config.t(), String.t(), map(), map()) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}
GetBucket (ListObjects) - lists the information about all objects in a bucket.
examples
Examples
iex> Aliyun.Oss.Bucket.get_bucket(config, "some-bucket", %{"prefix" => "foo/"})
{:ok, %Aliyun.Oss.Client.Response{
data: %{
"ListBucketResult" => %{
"Contents" => [
%{
"ETag" => ""D410293F000B000D00D"",
"key" => "foo/bar",
"LastModified" => "2018-09-12T02:59:41.000Z",
"Owner" => %{"DislayName" => "11111111", "ID" => "11111111"},
"Size" => "12345",
"StorageClass" => "IA",
"Type" => "Normal"
},
...
],
"Delimiter" => nil,
"IsTruncated" => true,
"Marker" => nil,
"MaxKeys" => 100,
"Name" => "some-bucket",
"NextMarker" => "XXXXX",
"Prefix" => "foo/"
}
},
headers: [
{"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
...
]
}
}
iex> Aliyun.Oss.Bucket.get_bucket(config, "unknown-bucket")
{:error,
%Aliyun.Oss.Client.Error{
status_code: 404,
parsed_details: %{
"ListBucketResult" => %{
"BucketName" => "unknown-bucket",
"Code" => "NoSuchBucket",
"HostId" => "unknown-bucket.oss-cn-shenzhen.aliyuncs.com",
"Message" => "The specified bucket does not exist.",
"RequestId" => "5BFF89955E29FF66F10B9763"
}
},
body: "<?xml version="1.0" encoding="UTF-8"?>...</xml>"
}
}
get_bucket_info(config, bucket)
@spec get_bucket_info(Aliyun.Oss.Config.t(), String.t()) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}
GetBucketInfo - gets the information about a bucket.
examples
Examples
iex> Aliyun.Oss.Bucket.get_bucket_info(config, "some-bucket")
{:ok, %Aliyun.Oss.Client.Response{
data: %{
"BucketInfo" => %{
"Bucket" => %{
"AccessControlList" => %{"Grant" => "private"},
"Comment" => nil,
"CreationDate" => "2018-08-29T01:52:03.000Z",
"DataRedundancyType" => "LRS",
"ExtranetEndpoint" => "oss-cn-shenzhen.aliyuncs.com",
"IntranetEndpoint" => "oss-cn-shenzhen-internal.aliyuncs.com",
"Location" => "oss-cn-shenzhen",
"Name" => "some-bucket",
"Owner" => %{
"DisplayName" => "11111111",
"ID" => "11111111"
},
"StorageClass" => "IA"
}
}
},
headers: [
{"Date", "Wed, 05 Dec 2018 02:34:57 GMT"}
]
}
get_bucket_location(config, bucket)
@spec get_bucket_location(Aliyun.Oss.Config.t(), String.t()) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}
GetBucketLocation - views the location information of a bucket.
examples
Examples
iex> Aliyun.Oss.Bucket.get_bucket_location(config, "some-bucket")
{:ok, %Aliyun.Oss.Client.Response{
data: %{"LocationConstraint" => "oss-cn-shenzhen"},
headers: [
{"Date", "Wed, 05 Dec 2018 02:34:57 GMT"}
]
}
}
list_buckets(config, query_params \\ %{})
@spec list_buckets(Aliyun.Oss.Config.t(), map()) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}
ListBuckets - lists the information about all buckets.
examples
Examples
iex> Aliyun.Oss.Bucket.list_buckets(config, %{"max-keys" => 5})
{:ok, %Aliyun.Oss.Client.Response{
data: %{
"Buckets" => %{
"Bucket" => [
%{
"CreationDate" => "2018-10-12T07:57:51.000Z",
"ExtranetEndpoint" => "oss-cn-shenzhen.aliyuncs.com",
"IntranetEndpoint" => "oss-cn-shenzhen-internal.aliyuncs.com",
"Location" => "oss-cn-shenzhen",
"Name" => "XXXXX",
"StorageClass" => "Standard"
},
...
]
},
"IsTruncated" => true,
"Marker" => nil,
"MaxKeys" => 5,
"NextMarker" => "XXXXX",
"Owner" => %{"DislayName" => "11111111", "ID" => "11111111"},
"Prefix" => nil
},
headers: [
{"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
...
]
}
}
iex> Aliyun.Oss.Bucket.list_buckets(config, %{"max-keys" => 100000})
{:error,
%Aliyun.Oss.Client.Error{
status_code: 400,
parsed_details: %{
"ArgumentName" => "max-keys",
"ArgumentValue" => "100000",
"Code" => "InvalidArgument",
"HostId" => "oss-cn-shenzhen.aliyuncs.com",
"Message" => "Argument max-keys must be an integer between 1 and 1000.",
"RequestId" => "5BFF8912332CCD8D560F65D9"
},
body: "<?xml version="1.0" encoding="UTF-8"?>...</xml>"
}
}
list_objects(config, bucket, query_params \\ %{}, sub_resources \\ %{})
@spec list_objects(Aliyun.Oss.Config.t(), String.t(), map(), map()) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}
GetBucketV2 (ListObjectsV2) - lists the information about all objects in a bucket.
examples
Examples
iex> Aliyun.Oss.Bucket.list_objects(config, "some-bucket", %{"prefix" => "foo/"})
{:ok, %Aliyun.Oss.Client.Response{
data: %{
"ListBucketResult" => %{
"Contents" => [
%{
"ETag" => ""D410293F000B000D00D"",
"key" => "foo/bar",
"LastModified" => "2018-09-12T02:59:41.000Z",
"Owner" => %{"DislayName" => "11111111", "ID" => "11111111"},
"Size" => "12345",
"StorageClass" => "IA",
"Type" => "Normal"
},
...
],
"Delimiter" => nil,
"IsTruncated" => true,
"Marker" => nil,
"KeyCount" => 100,
"MaxKeys" => 100,
"Name" => "some-bucket",
"NextContinuationToken" => "XXXXX",
"Prefix" => "foo/"
}
},
headers: [
{"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
...
]
}
}
iex> Aliyun.Oss.Bucket.list_objects(config, "unknown-bucket")
{:error,
%Aliyun.Oss.Client.Error{
status_code: 404,
parsed_details: %{
"ListBucketResult" => %{
"BucketName" => "unknown-bucket",
"Code" => "NoSuchBucket",
"HostId" => "unknown-bucket.oss-cn-shenzhen.aliyuncs.com",
"Message" => "The specified bucket does not exist.",
"RequestId" => "5BFF89955E29FF66F10B9763"
}
},
body: "<?xml version="1.0" encoding="UTF-8"?>...</xml>"
}
}
put_bucket(config, bucket, headers \\ %{}, sub_resources \\ %{}, body \\ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<CreateBucketConfiguration>\n <StorageClass>Standard</StorageClass>\n</CreateBucketConfiguration>\n")
@spec put_bucket(Aliyun.Oss.Config.t(), String.t(), map(), map(), String.t()) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}
PutBucket - creates a bucket.
examples
Examples
iex> Aliyun.Oss.Bucket.put_bucket(config, "new-bucket", %{"x-oss-acl" => "private"})
{:ok,
%Aliyun.Oss.Client.Response{
data: "",
headers: [
{"Server", "AliyunOSS"},
{"Date", "Fri, 11 Jan 2019 04:35:39 GMT"},
{"Content-Length", "0"},
{"Connection", "keep-alive"},
{"x-oss-request-id", "5C381D000000000000000000"},
{"Location", "/new-bucket"},
{"x-oss-server-time", "438"}
]
}}
iex> Aliyun.Oss.Bucket.put_bucket(config, "new-bucket", %{"x-oss-acl" => "invalid-permission"}) # get error
{:error,
%Aliyun.Oss.Client.Error{
parsed_details: %{
"ArgumentName" => "x-oss-acl",
"ArgumentValue" => "invalid-permission",
"Code" => "InvalidArgument",
"HostId" => "new-bucket.oss-cn-shenzhen.aliyuncs.com",
"Message" => "no such bucket access control exists",
"RequestId" => "5C3000000000000000000000"
},
body: "<?xml version="1.0" encoding="UTF-8"?>...</xml>",
status_code: 400
}}