Uploadex v0.1.2 Uploadex View Source

Context Helper functions for handling files.

Link to this section Summary

Functions

Inserts the changeset and store the record files in a database transaction, so if the files fail to be stored the record will not be created.

Deletes the record and all of its files. This is not in a database transaction, since the delete operation never returns errors.

Returns the record's files (as defined in the definition get_files) URL, replacing the uploader.base_directory() with the endpoint URL.

Similar to get_files_url/3, but instead of returning all files defined in the definition get_files, returns the URL for the specified files.

Similar to update_with_file/3, but does not delete previous files.

Updates the record and its files in a database transaction, so if the files fail to be stored the record will not be created.

Link to this section Functions

Link to this function

create_with_file(changeset, uploader) View Source

Inserts the changeset and store the record files in a database transaction, so if the files fail to be stored the record will not be created.

Link to this function

delete_with_file(record, uploader) View Source

Deletes the record and all of its files. This is not in a database transaction, since the delete operation never returns errors.

Link to this function

get_files_url(uploader, record, endpoint_url) View Source

Returns the record's files (as defined in the definition get_files) URL, replacing the uploader.base_directory() with the endpoint URL.

To provide the endpoint URL, there are two options:

  • Provide the endpoint_url directly as a string
  • Provide the Phoenix.Endpoint module
Link to this function

get_files_url(uploader, record, files, endpoint_url) View Source

Similar to get_files_url/3, but instead of returning all files defined in the definition get_files, returns the URL for the specified files.

This is useful when one record has multiple file fields.

Link to this function

update_with_file(changeset, uploader) View Source

Similar to update_with_file/3, but does not delete previous files.

Link to this function

update_with_file(changeset, previous_record, uploader) View Source

Updates the record and its files in a database transaction, so if the files fail to be stored the record will not be created.

This function also deletes files that are no longer referenced.