View Source Trunk.Storage.Filesystem (trunk v1.5.1)
A Trunk.Storage
implementation for the local file system.
Summary
Functions
Generates a URL for the storage directory and file
Copies the file within the file system.
Deletes the file from the file system.
Callback implementation for Trunk.Storage.retrieve/4
.
Saves the file to the file system.
Functions
Generates a URL for the storage directory and file
directory
- The relative directory where the file is savedfilename
- The name of the file that was previous savedopts
- The options for the storage systembase_uri:
(optional) The base url to join the path to
Example:
Trunk.Storage.Filesystem.build_url("path/to", "file.ext")
#=> "path/to/file.ext"
Trunk.Storage.Filesystem.build_url("path/to", "file.ext", base_uri: "http://example.com")
#=> "http://example.com/path/to/file.ext"
Trunk.Storage.Filesystem.build_url("path/to", "file.ext", base_uri: "http://example.com/uploads/")
#=> "http://example.com/uploads/path/to/file.ext"
Trunk.Storage.Filesystem.build_url("path/to", "file.ext", base_uri: "/uploads/")
#=> "/uploads/path/to/file.ext"
@spec copy( directory :: String.t(), filename :: String.t(), to_directory :: String.t(), to_filename :: String.t(), opts :: keyword() ) :: :ok | {:error, :file.posix()}
Copies the file within the file system.
directory
- The relative directory within which to find the filefilename
- The name of the file to be copied fromto_directory
- The relative directory within which to copy the fileto_filename
- The name of the file to be copied toopts
- The options for the storage systempath:
(required) The base path within which to save filesacl:
(optional) The file mode to store the file (accepts octal0o644
or string"0644"
). SeeFile.chmod/2
for more info.
Example:
The file will be copied from /opts/uploads/path/to/file.ext to /opts/uploads/copied/to/file.copy
Trunk.Storage.Filesystem.copy("path/to/", "file.ext", "copied/to/", "file.copy", path: "/opt/uploads")
@spec delete(String.t(), String.t(), keyword()) :: :ok | {:error, :file.posix()}
Deletes the file from the file system.
directory
- The relative directory within which to store the filefilename
- The name of the file to be savedopts
- The options for the storage systempath:
(required) The base path within which to save files
Example:
The file will be removed from /opts/uploads/path/to/file.ext
Trunk.Storage.Filesystem.delete("path/to/", "file.ext", path: "/opt/uploads")
Callback implementation for Trunk.Storage.retrieve/4
.
@spec save( directory :: String.t(), filename :: String.t(), source_path :: String.t(), opts :: keyword() ) :: :ok | {:error, :file.posix()}
Saves the file to the file system.
directory
- The relative directory within which to store the filefilename
- The name of the file to be savedsource_path
- The full path to the file to be stored. This is a path to the uploaded file or a temporary file that has undergone transformationopts
- The options for the storage systempath:
(required) The base path within which to save filesacl:
(optional) The file mode to store the file (accepts octal0o644
or string"0644"
). SeeFile.chmod/2
for more info.
Example:
The file will be saved to /opts/uploads/path/to/file.ext
Trunk.Storage.Filesystem.save("path/to/", "file.ext", "/tmp/uploaded_file.ext", path: "/opt/uploads")