FileStore (file_store v0.2.1)
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
Delete a file from the store.
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 all of the files in the store.
Configures a new store.
Read the contents of a file in store into memory.
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
key()
Specs
key() :: binary()
path()
Specs
path() :: Path.t()
Specs
url()
Specs
url() :: binary()
Link to this section Functions
delete(store, key)
Specs
Delete a file from the store.
Examples
iex> FileStore.delete(store, "foo") :ok
download(store, key, destination)
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
get_public_url(store, key, opts \\ [])
Specs
Get URL for your file, assuming that the file is publicly accessible.
Examples
iex> FileStore.get_public_url(store, "foo")
"https://mybucket.s3-us-east-1.amazonaws.com/foo"
get_signed_url(store, key, opts \\ [])
Specs
Generate a signed URL for your file. Any user with this URL should be able to access the file.
Examples
iex> FileStore.get_signed_url(store, "foo")
{:ok, "https://s3.amazonaws.com/mybucket/foo?X-AMZ-Expires=3600&..."}
list!(store)
Specs
list!(t()) :: Enumerable.t()
List all of the files in the store.
Examples
iex> Enum.to_list(FileStore.list!(store))
["foo/bar"]
new(opts)
Specs
Configures a new store.
Examples
iex> FileStore.new(adapter: FileStore.Adapters.Memory)
%FileStore{adapter: FileStore.Adapters.Memory, config: %{}}
read(store, key)
Specs
Read the contents of a file in store into memory.
Examples
iex> FileStore.read(store, "foo")
{:ok, "hello world"}
stat(store, key)
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}}
upload(store, source, key)
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
write(store, key, content)
Specs
Write a file to the store. If a file with the given key
already exists, it will be overwritten.
Examples
iex> FileStore.write(store, "foo", "hello world")
:ok