View Source FileStore protocol (file_store v0.4.0)
FileStore allows you to read, write, upload, download, and interact with files, regardless of where they are stored.
Adapters
This package ships with the following adapters:
The documentation for each adapter includes an example that demonstrates it's usage.
Link to this section Summary
Functions
Copy a file to a new location.
Delete a file from the store.
Delete files in bulk.
Download a file from the store and save it to the given path
.
Get URL for your file, assuming that the file is publicly accessible.
Generate a signed URL for your file. Any user with this URL should be able to access the file.
List files in the store.
Read the contents of a file in store into memory.
Renames a file from one name to another.
Retrieve information about a file from the store.
Upload a file to the store. If a file with the given key
already exists, it will be overwritten.
Write a file to the store. If a file with the given key
already exists, it will be overwritten.
Link to this section Types
Link to this section Functions
Specs
Copy a file to a new location.
Examples
iex> FileStore.copy(store, "path/foo.txt", "path/bar.txt")
:ok
Specs
Delete a file from the store.
Examples
iex> FileStore.delete(store, "foo") :ok
Specs
delete_all(t(), delete_all_opts()) :: :ok | {:error, term()}
Delete files in bulk.
Options
:prefix
- Only delete keys matching the given prefix.
Examples
iex> FileStore.delete_all(store) :ok
iex> FileStore.delete_all(store, prefix: "foo/") :ok
Specs
Download a file from the store and save it to the given path
.
Examples
iex> FileStore.download(store, "foo", "/path/to/bar.txt")
:ok
Specs
get_public_url(t(), key(), public_url_opts()) :: binary()
Get URL for your file, assuming that the file is publicly accessible.
Options
:content_type
- Force theContent-Type
of the response.:disposition
- Force theContent-Disposition
of the response.
Examples
iex> FileStore.get_public_url(store, "foo")
"https://mybucket.s3-us-east-1.amazonaws.com/foo"
Specs
get_signed_url(t(), key(), signed_url_opts()) :: {:ok, binary()} | {:error, term()}
Generate a signed URL for your file. Any user with this URL should be able to access the file.
Options
:expires_in
- The number of seconds before the URL expires.:content_type
- Force theContent-Type
of the response.:disposition
- Force theContent-Disposition
of the response.
Examples
iex> FileStore.get_signed_url(store, "foo")
{:ok, "https://s3.amazonaws.com/mybucket/foo?X-AMZ-Expires=3600&..."}
Specs
list!(t(), list_opts()) :: Enumerable.t()
List files in the store.
Options
:prefix
- Only return keys matching the given prefix.
Examples
iex> Enum.to_list(FileStore.list!(store))
["bar", "foo/bar"]
iex> Enum.to_list(FileStore.list!(store, prefix: "foo"))
["foo/bar"]
Specs
Read the contents of a file in store into memory.
Examples
iex> FileStore.read(store, "foo")
{:ok, "hello world"}
Specs
Renames a file from one name to another.
Note: Some underlying adapters can not do this in an atomic fashion.
Examples
iex> FileStore.rename(store, "path/foo.txt", "path/bar.txt")
:ok
Specs
stat(t(), key()) :: {:ok, FileStore.Stat.t()} | {:error, term()}
Retrieve information about a file from the store.
Examples
iex> FileStore.stat(store, "foo")
{:ok, %FileStore.Stat{key: "foo", etag: "2e5pd429", size: 24}}
Specs
Upload a file to the store. If a file with the given key
already exists, it will be overwritten.
Examples
iex> FileStore.upload(store, "/path/to/bar.txt", "foo")
:ok
Specs
write(t(), key(), binary(), write_opts()) :: :ok | {:error, term()}
Write a file to the store. If a file with the given key
already exists, it will be overwritten.
Options
* `:content_type` - Sets the content type hint for the adapter.
* `:disposition` - Sets the content disposition hint for the adapter.
Examples
iex> FileStore.write(store, "foo", "hello world")
:ok