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
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
Specs
download(config(), String.t(), VBT.Aws.S3.Hostable.t()) :: VBT.Aws.response(s3_response())
Downloads the given object from S3.
Specs
download_url(config(), String.t(), VBT.Aws.S3.Hostable.t()) :: String.t()
Returns the presigned download url for the given object.
Specs
upload( config(), String.t(), upload_source(), VBT.Aws.S3.Hostable.t(), Keyword.t() ) :: VBT.Aws.response(s3_response())
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 uploadbinary
- 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
.
Specs
upload_url(config(), String.t(), VBT.Aws.S3.Hostable.t()) :: String.t()
Returns the presigned upload url for the given object.