m_media (zotonic_core v1.0.0-rc.11)

Model for medium database

Link to this section Summary

Functions

Delete the medium at the id. The file is queued for later deletion.
Get the medium record that depicts the resource id. "depiction" Predicates are preferred, if they are missing then the attached medium record itself is returned. We must be able to generate a preview from the medium.
Return the list of resources that is depicted by the medium (excluding the rsc itself)
Download a file from a http or data url.
Duplicate the media item from the id to the new-id. Called by m_rsc:duplicate/3
Check if a medium record exists. The argument should be undefined, or a (textual) integer.
Get the medium record with the id
Fetch a medium by filename
Return the identification of a medium. Used by z_media_identify:identify()
Make a new resource for the file, when the file is not in the archive dir then a copy is made in the archive dir
Insert a medium, together with rsc props and an optional preview_url. This is used for importing media.
Make a new resource for the file based on a URL.
Fetch the value for the key from a model source
Move a medium between resources, iff the destination doesn't have an associated medium. This is called when merging two resources (and the FromId is subsequently deleted).
Replace or insert a medium record for the page. This is useful for non-file related media. Resets all non mentioned attributes.
Replaces a medium file, when the file is not in archive then a copy is made in the archive. When the resource is in the media category, then the category is adapted depending on the mime type of the uploaded file.
Re-upload a file so that identify and previews are regenerated.
Save a preview for a medium record. The data is saved to a file in the archive directory.
Save a new file from a preview_url as the preview of a medium

Link to this section Types

-type media_url() :: binary() | string().

Link to this section Functions

Link to this function

delete(Id, Context)

-spec delete(m_rsc:resource_id(), z:context()) -> ok | {error, term()}.
Delete the medium at the id. The file is queued for later deletion.
Link to this function

depiction(Id, Context)

-spec depiction(m_rsc:resource_id(), z:context()) -> map() | undefined.
Get the medium record that depicts the resource id. "depiction" Predicates are preferred, if they are missing then the attached medium record itself is returned. We must be able to generate a preview from the medium.
Link to this function

depicts(Id, Context)

-spec depicts(m_rsc:resource_id(), z:context()) -> [m_rsc:resource_id()].
Return the list of resources that is depicted by the medium (excluding the rsc itself)
Link to this function

download_file(Url, Context)

Download a file from a http or data url.
Link to this function

download_file(Url, Options, Context)

Link to this function

duplicate(FromId, ToId, Context)

-spec duplicate(m_rsc:resource(), m_rsc:resource(), z:context()) -> ok | {error, term()}.
Duplicate the media item from the id to the new-id. Called by m_rsc:duplicate/3
Link to this function

exists(Name, Context)

-spec exists(undefined | string() | binary() | integer(), z:context()) -> boolean().
Check if a medium record exists. The argument should be undefined, or a (textual) integer.
Link to this function

get(Id, Context)

-spec get(m_rsc:resource() | undefined, z:context()) -> z_media_identify:media_info() | undefined.
Get the medium record with the id
Link to this function

get_by_filename(Filename, Context)

-spec get_by_filename(binary(), z:context()) -> z_media_identify:media_info() | undefined.
Fetch a medium by filename
Link to this function

identify(Id, Context)

-spec identify(m_rsc:resource_id(), z:context()) ->
            {ok, z_media_identify:media_info()} | {error, term()}.
Return the identification of a medium. Used by z_media_identify:identify()
Link to this function

insert_file(File, Context)

-spec insert_file(file:filename_all() | #upload{}, z:context()) ->
               {ok, m_rsc:resource_id()} | {error, term()}.
Make a new resource for the file, when the file is not in the archive dir then a copy is made in the archive dir
Link to this function

insert_file(File, RscProps, Context)

-spec insert_file(file:filename_all() | #upload{}, m_rsc:props_all(), z:context()) ->
               {ok, m_rsc:resource_id()} | {error, term()}.
Link to this function

insert_file(File, RscProps, Options, Context)

-spec insert_file(file:filename_all() | #upload{}, m_rsc:props_all(), list(), z:context()) ->
               {ok, m_rsc:resource_id()} | {error, term()}.
Link to this function

insert_medium(Medium, RscProps, Options, Context)

Insert a medium, together with rsc props and an optional preview_url. This is used for importing media.
Link to this function

insert_url(Url, Context)

-spec insert_url(media_url(), z:context()) -> {ok, pos_integer()} | {error, term()}.
Make a new resource for the file based on a URL.
Link to this function

insert_url(Url, RscProps, Context)

-spec insert_url(media_url(), m_rsc:props_all(), z:context()) -> {ok, pos_integer()} | {error, term()}.
Link to this function

insert_url(Url, RscProps, Options, Context)

-spec insert_url(media_url(), m_rsc:props_all(), list(), z:context()) ->
              {ok, pos_integer()} | {error, term()}.
Link to this function

is_unique_file(Filename, Context)

Link to this function

m_get(Rest, Msg, Context)

-spec m_get(list(), zotonic_model:opt_msg(), z:context()) -> zotonic_model:return().
Fetch the value for the key from a model source
Link to this function

make_preview_unique(RscId, Extension, Context)

-spec make_preview_unique(integer() | insert_rsc, binary(), z:context()) -> file:filename().
Link to this function

merge(WinnerId, LoserId, Context)

Move a medium between resources, iff the destination doesn't have an associated medium. This is called when merging two resources (and the FromId is subsequently deleted).
Link to this function

mime_to_category(Mime)

-spec mime_to_category(string() | binary()) -> image | video | audio | document.
Link to this function

replace(Id, Props, Context)

-spec replace(m_rsc:resource_id(), map(), z:context()) -> ok | {error, term()}.
Replace or insert a medium record for the page. This is useful for non-file related media. Resets all non mentioned attributes.
Link to this function

replace_file(File, RscId, Context)

Replaces a medium file, when the file is not in archive then a copy is made in the archive. When the resource is in the media category, then the category is adapted depending on the mime type of the uploaded file.
Link to this function

replace_file(File, RscId, RscProps, Context)

Link to this function

replace_file(File, RscId, RscProps, Opts, Context)

Link to this function

replace_file(File, RscId, RscProps, MediaInfo, Opts, Context)

Link to this function

replace_medium(Medium, RscId, RscProps, Options, Context)

Link to this function

replace_url(Url, RscId, RscProps, Context)

Link to this function

replace_url(Url, RscId, RscProps, Options, Context)

Link to this function

reupload(Id, Context)

-spec reupload(m_rsc:resource_id(), z:context()) -> {ok, m_rsc:resource_id()} | {error, term()}.
Re-upload a file so that identify and previews are regenerated.
Link to this function

save_preview(RscId, Data, Mime, Context)

-spec save_preview(m_rsc:resource_id(), iodata(), binary() | string(), z:context()) ->
                {ok, file:filename_all()} | {error, eacces | term()}.
Save a preview for a medium record. The data is saved to a file in the archive directory.
Link to this function

save_preview_url(RscId, Url, Context)

Save a new file from a preview_url as the preview of a medium