Aliyun.Oss.Object (aliyun_oss v2.0.0)

Object operations - basic operations.

Other operations can be found in:

Link to this section Summary

Functions

AppendObject - uploads an object by appending the content of the object to an existing object.

CopyObject - copies objects within a bucket or between buckets in the same region.

DeleteMultipleObjects - deletes multiple objects from a bucket.

GetObjectMeta - gets the metadata of an object, including ETag, Size, and LastModified.

Creates a signed URL for accessing an object.

RestoreObject - restores an Archive object or a Cold Archive object.

SelectObject - executes SQL statements to perform operations on an object and obtains the execution results.

CreateSelectObjectMeta - 获取目标文件总的行数,总的列数(对于 CSV 文件),以及 Splits 个数。

Signs Post Policy, and returns the encoded Post Policy and its signature.

Link to this section Types

@type error() ::
  %Aliyun.Oss.Client.Error{
    body: String.t(),
    parsed_details: map(),
    status_code: integer()
  }
  | atom()

Link to this section Functions

Link to this function

append_object(config, bucket, object, body, position, headers \\ %{})

@spec append_object(
  Aliyun.Oss.Config.t(),
  String.t(),
  String.t(),
  String.t(),
  integer(),
  map()
) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

AppendObject - uploads an object by appending the content of the object to an existing object.

examples

Examples

iex> Aliyun.Oss.Object.append_object(config, "some-bucket", "some-object", "CONTENT", 0)
{:ok, %Aliyun.Oss.Client.Response{
    data: "",
    headers: [
      {"Server", "AliyunOSS"},
      {"Date", "Fri, 01 Mar 2019 05:57:23 GMT"},
      {"Content-Length", "0"},
      {"Connection", "keep-alive"},
      {"x-oss-request-id", "5C0000000000000000000000"},
      {"ETag", ""B38D0000000000000000000000000000""},
      {"x-oss-next-append-position", "10"},
      {"x-oss-hash-crc64ecma", "8000000000000000000"},
      {"x-oss-server-time", "17"}
    ]
  }
}
Link to this function

copy_object(config, arg1, arg2, headers \\ %{})

@spec copy_object(
  Aliyun.Oss.Config.t(),
  {String.t(), String.t()},
  {String.t(), String.t()},
  map()
) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

CopyObject - copies objects within a bucket or between buckets in the same region.

examples

Examples

iex> Aliyun.Oss.Object.copy_object(config, {"source-bucket", "source-object"}, {"target-bucket", "target-object"})
{:ok, %Aliyun.Oss.Client.Response{
    data: %{
      "CopyObjectResult" => %{
        "ETag" => ""D2D50000000000000000000000000000"",
        "LastModified" => "2019-02-27T09:21:13.000Z"
      }
    },
    headers: [
      {"Server", "AliyunOSS"},
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
Link to this function

delete_multiple_objects(config, bucket, objects, options \\ [])

@spec delete_multiple_objects(Aliyun.Oss.Config.t(), String.t(), [String.t()],
  encoding_type: :url,
  quiet: boolean()
) :: {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

DeleteMultipleObjects - deletes multiple objects from a bucket.

options

Options

  • :encoding_type - Accept value: :url
  • :quiet - Set true to enable the quiet mode, default is false

examples

Examples

iex> Aliyun.Oss.Object.delete_multiple_objects(config, "some-bucket", ["object1", "object2"])
{:ok, %Aliyun.Oss.Client.Response{
    data: %{
      "DeleteResult" => %{
        "Deleted" => [%{"key" => "object1"}, %{"key" => "object2"}]
      }
    },
    headers: [
      {"Server", "AliyunOSS"},
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
Link to this function

delete_object(config, bucket, object, sub_resources \\ %{})

DeleteObject - deletes an object.

examples

Examples

iex> Aliyun.Oss.Object.delete_object(config, "some-bucket", "some-object")
{:ok, %Aliyun.Oss.Client.Response{
    data: "",
    headers: [
      {"Server", "AliyunOSS"},
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
Link to this function

get_object(config, bucket, object, headers \\ %{}, sub_resources \\ %{})

@spec get_object(Aliyun.Oss.Config.t(), String.t(), String.t(), map(), map()) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

GetObject - gets an object.

examples

Examples

iex> Aliyun.Oss.Object.get_object(config, "some-bucket", "some-object")
{:ok, %Aliyun.Oss.Client.Response{
    data: <<208, 207, 17, 224, 161, 177, 26, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 62, 0, 3, 0, 254, 255, 9, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
      0, 0, 0, ...>>,
    headers: [
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
Link to this function

get_object_meta(config, bucket, object)

@spec get_object_meta(Aliyun.Oss.Config.t(), String.t(), String.t()) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

GetObjectMeta - gets the metadata of an object, including ETag, Size, and LastModified.

The content of the object is not returned.

examples

Examples

iex> Aliyun.Oss.Object.get_object_meta(config, "some-bucket", "some-object")
{:ok,
%Aliyun.Oss.Client.Response{
  data: "",
  headers: [
    {"Server", "AliyunOSS"},
    {"Date", "Wed, 05 Dec 2018 05:50:02 GMT"},
    {"Content-Length", "0"},
    {"Connection", "keep-alive"},
    {"x-oss-request-id", "5C0000000000000000000000"},
    {"ETag", ""D4100000000000000000000000000000""},
    {"x-oss-hash-crc64ecma", "0"},
    {"Last-Modified", "Mon, 15 Oct 2018 01:38:47 GMT"},
    {"x-oss-server-time", "19"}
  ]
}}
Link to this function

head_object(config, bucket, object, headers \\ %{}, sub_resources \\ %{})

@spec head_object(Aliyun.Oss.Config.t(), String.t(), String.t(), map(), map()) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

HeadObject - gets the metadata of an object.

The content of the object is not returned.

examples

Examples

iex> Aliyun.Oss.Object.head_object(config, "some-bucket", "some-object")
{:ok,
%Aliyun.Oss.Client.Response{
  data: "",
  headers: [
    {"Server", "AliyunOSS"},
    {"Date", "Wed, 05 Dec 2018 05:50:02 GMT"},
    {"Content-Type", "application/octet-stream"},
    {"Content-Length", "0"},
    {"Connection", "keep-alive"},
    {"x-oss-request-id", "5C0000000000000000000000"},
    {"Accept-Ranges", "bytes"},
    {"ETag", ""D4100000000000000000000000000000""},
    {"Last-Modified", "Mon, 15 Oct 2018 01:38:47 GMT"},
    {"x-oss-object-type", "Normal"},
    {"x-oss-hash-crc64ecma", "0"},
    {"x-oss-storage-class", "IA"},
    {"Content-MD5", "1B2M2Y8AsgTpgAmY7PhCfg=="},
    {"x-oss-server-time", "19"}
  ]
}}

iex> Aliyun.Oss.Object.head_object(config, "some-bucket", "unknown-object")
{:error, %Aliyun.Oss.Client.Error{status_code: 404, body: "", parsed_details: nil}}
Link to this function

object_url(config, bucket, object, expires)

@spec object_url(Aliyun.Oss.Config.t(), String.t(), String.t(), integer()) ::
  String.t()

Creates a signed URL for accessing an object.

examples

Examples

iex> expires = Timex.now() |> Timex.shift(days: 1) |> Timex.to_unix()
iex> Aliyun.Oss.Object.object_url(config, "some-bucket", "some-object", expires)
"http://some-bucket.oss-cn-hangzhou.aliyuncs.com/oss-api.pdf?OSSAccessKeyId=nz2pc56s936**9l&Expires=1141889120&Signature=vjbyPxybdZaNmGa%2ByT272YEAiv4%3D"
Link to this function

put_object(config, bucket, object, body, headers \\ %{}, sub_resources \\ %{})

@spec put_object(
  Aliyun.Oss.Config.t(),
  String.t(),
  String.t(),
  String.t(),
  map(),
  map()
) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

PutObject - uploads objects.

examples

Examples

iex> Aliyun.Oss.Object.put_object(config, "some-bucket", "some-object", "CONTENT")
{:ok, %Aliyun.Oss.Client.Response{
    data: "",
    headers: [
      {"Server", "AliyunOSS"},
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
Link to this function

restore_object(config, bucket, object)

@spec restore_object(Aliyun.Oss.Config.t(), String.t(), String.t()) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

RestoreObject - restores an Archive object or a Cold Archive object.

examples

Examples

iex> Aliyun.Oss.Object.restore_object(config, "some-bucket", "some-object")
{:ok, %Aliyun.Oss.Client.Response{
    data: "",
    headers: [
      {"Server", "AliyunOSS"},
      {"Date", "Fri, 01 Mar 2019 06:38:21 GMT"},
      {"Content-Length", "0"},
      {"Connection", "keep-alive"},
      {"x-oss-request-id", "5C7000000000000000000000"},
      {"x-oss-server-time", "7"}
    ]
  }
}
Link to this function

select_object(config, bucket, object, select_request, options \\ [])

@spec select_object(
  Aliyun.Oss.Config.t(),
  String.t(),
  String.t(),
  String.t() | map(),
  keyword()
) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

SelectObject - executes SQL statements to perform operations on an object and obtains the execution results.

options

Options

  • :format - specifies the request syntax:
    • available values: :json, :csv
    • default value: :csv

examples

Examples

iex> select_request = %{
  "SelectRequest" => %{
    "Expression" => "c2VsZWN0ICogZnJvbSBvc3NvYmplY3QuY29udGFjdHNbKl0gcyB3aGVyZSBzLmFnZSA9IDI3",
    "InputSerialization" => %{"JSON" => %{"Type" => "DOCUMENT"}},
    "OutputSerialization" => %{"JSON" => %{"RecordDelimiter" => "LA=="}}
  }
}
iex> Aliyun.Oss.Object.select_object(config, "some-bucket", "some-object", select_request, format: :json)
{:ok, %Aliyun.Oss.Client.Response{
    data: <<208, 207, 17, 224, 161, 177, 26, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 62, 0, 3, 0, 254, 255, 9, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
      0, 0, 0, ...>>,
    headers: [
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
iex> select_request = ~S[
  <SelectRequest>
      <Expression>c2VsZWN0ICogZnJvbSBvc3NvYmplY3QuY29udGFjdHNbKl0gcyB3aGVyZSBzLmFnZSA9IDI3</Expression>
      <InputSerialization>
      <JSON>
          <Type>DOCUMENT</Type>
      </JSON>
      </InputSerialization>
      <OutputSerialization>
      <JSON>
          <RecordDelimiter>LA==</RecordDelimiter>
      </JSON>
      </OutputSerialization>
  </SelectRequest>
]
iex> Aliyun.Oss.Object.select_object(config, "some-bucket", "some-object", select_request, format: :json)
{:ok, %Aliyun.Oss.Client.Response{
    data: <<208, 207, 17, 224, 161, 177, 26, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 62, 0, 3, 0, 254, 255, 9, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
      0, 0, 0, ...>>,
    headers: [
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
Link to this function

select_object_meta(config, bucket, object, select_request, options \\ [])

@spec select_object_meta(
  Aliyun.Oss.Config.t(),
  String.t(),
  String.t(),
  String.t() | map(),
  keyword()
) ::
  {:error, error()} | {:ok, Aliyun.Oss.Client.Response.t()}

CreateSelectObjectMeta - 获取目标文件总的行数,总的列数(对于 CSV 文件),以及 Splits 个数。

如果该信息不存在,则会扫描整个文件,分析并记录下 CSV 文件的上述信息。重复调用则会保存上述信息而不必重新扫描整个文件。

TODO: fix the doc

options

Options

  • :format - specifies the request syntax:
    • available values: :json, :csv
    • default value: :csv

examples

Examples

iex> select_request = %{
  "JsonMetaRequest" => %{
    "InputSerialization" => %{"JSON" => %{"Type" => "LINES"}},
    "OverwriteIfExisting" => "false"
  }
}
iex> Aliyun.Oss.Object.select_object_meta(config, "some-bucket", "some-object", select_request, format: :json)
{:ok, %Aliyun.Oss.Client.Response{
    data: <<208, 207, 17, 224, 161, 177, 26, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 62, 0, 3, 0, 254, 255, 9, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
      0, 0, 0, ...>>,
    headers: [
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
iex> select_request = ~S[
  <?xml version="1.0"?>
  <JsonMetaRequest>
      <InputSerialization>
          <JSON>
              <Type>LINES</Type>
          </JSON>
      </InputSerialization>
      <OverwriteIfExisting>false</OverwriteIfExisting>
  </JsonMetaRequest>
]
iex> Aliyun.Oss.Object.select_object_meta(config, "some-bucket", "some-object", select_request, format: :json)
{:ok, %Aliyun.Oss.Client.Response{
    data: <<208, 207, 17, 224, 161, 177, 26, 225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 62, 0, 3, 0, 254, 255, 9, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18,
      0, 0, 0, ...>>,
    headers: [
      {"Date", "Wed, 05 Dec 2018 02:34:57 GMT"},
      ...
    ]
  }
}
Link to this function

sign_post_policy(config, policy)

@spec sign_post_policy(Aliyun.Oss.Config.t(), map()) :: %{
  policy: String.t(),
  signature: String.t()
}

Signs Post Policy, and returns the encoded Post Policy and its signature.

examples

Examples

iex> policy = %{
...>  "conditions" => [
...>    ["content-length-range", 0, 10485760],
...>    %{"bucket" => "ahaha"},
...>    %{"A" => "a"},
...>    %{"key" => "ABC"}
...>  ],
...>  "expiration" => "2013-12-01T12:00:00Z"
...>}
iex> Aliyun.Oss.Object.sign_post_policy(config, policy)
%{
  policy: "eyJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMCwxMDQ4NTc2MF0seyJidWNrZXQiOiJhaGFoYSJ9LHsiQSI6ImEifSx7ImtleSI6IkFCQyJ9XSwiZXhwaXJhdGlvbiI6IjIwMTMtMTItMDFUMTI6MDA6MDBaIn0=",
  signature: "W835KpLsL6k1/oo28RcsEflB6hw="
}
Link to this function

signed_url(config, bucket, object, expires, method, headers, sub_resources \\ %{})

@spec signed_url(
  Aliyun.Oss.Config.t(),
  String.t(),
  String.t(),
  integer(),
  String.t(),
  map(),
  map()
) ::
  String.t()

Creates a signed URL for an object.

examples

Examples

iex> expires = Timex.now() |> Timex.shift(days: 1) |> Timex.to_unix()
iex> Aliyun.Oss.Object.signed_url(config, "some-bucket", "some-object", expires, "GET", %{"Content-Type" => ""})
"http://some-bucket.oss-cn-hangzhou.aliyuncs.com/oss-api.pdf?OSSAccessKeyId=nz2pc5*******9l&Expires=1141889120&Signature=vjbyPxybdZ*****************v4%3D"
iex> Aliyun.Oss.Object.signed_url(config, "some-bucket", "some-object", expires, "PUT", %{"Content-Type" => "text/plain"})
"http://some-bucket.oss-cn-hangzhou.aliyuncs.com/oss-api.pdf?OSSAccessKeyId=nz2pc5*******9l&Expires=1141889120&Signature=vjbyPxybdZ*****************v4%3D"