VBT.Aws.S3 (vbt v0.1.0) View Source

Helper for performing actions on S3.

When making requests to S3, the VBT.Aws.client/0 function is invoked to determine the actual client module. Consequently, you can use VBT.Aws.Test to test this module.

Link to this section Summary

Functions

Downloads the given object from S3.

Returns the presigned download url for the given object.

Uploads the source to the path of the given target (hostable object).

Returns the presigned upload url for the given object.

Link to this section Types

Specs

config() :: %{
  scheme: String.t(),
  host: String.t(),
  region: String.t(),
  access_key_id: String.t(),
  secret_access_key: String.t()
}

Specs

s3_response() :: %{
  :body => String.t(),
  :headers => [{String.t(), String.t()}],
  optional(:status_code) => pos_integer()
}

Specs

upload_source() :: binary() | {:file, Path.t()} | Enumerable.t()

Link to this section Functions

Link to this function

download(config, bucket, object)

View Source

Specs

Downloads the given object from S3.

Link to this function

download_url(config, bucket, object)

View Source

Specs

download_url(config(), String.t(), VBT.Aws.S3.Hostable.t()) :: String.t()

Returns the presigned download url for the given object.

Link to this function

upload(config, bucket, source, target, opts \\ [])

View Source

Specs

Uploads the source to the path of the given target (hostable object).

Source can be one of the following:

  • {:file, String.t} - path to a local file to upload
  • binary - content to upload
  • enumerable of binaries - chunks of data to upload

The content is uploaded in chunks of 5 MiB. Notice that if you pass an enumerable of binaries, the input chunks won't affect the upload chunks.

Testing

To test this function, you can use VBT.Aws.Test:

test "upload" do
  Aws.Test.stub_request("")

  assert S3.upload(config, bucket, content, target) == {:ok, ""}

  path = S3.Hostable.path(target)
  assert_received {:aws_request, %ExAws.S3.Upload{bucket: ^bucket, path: ^path} = req, _}
  chunks = Enum.to_list(req.src)
  uploaded_content = IO.iodata_to_binary(chunks)

  # make assertions on uploaded_content
end

Note: opts are any options accepted by ExAws.S3.upload/4. This should correspond to ExAws.S3.upload_opts/0. However, this type is slightly incorrect, and using it leads to dialyzer errors, so the spec of this function uses a more relaxed Keyword.t.

Link to this function

upload_url(config, bucket, object)

View Source

Specs

upload_url(config(), String.t(), VBT.Aws.S3.Hostable.t()) :: String.t()

Returns the presigned upload url for the given object.