hecate_plugin_files (hecate_sdk v0.6.2)

View Source

File upload/download helper for plugins.

Handles multipart uploads and chunked downloads via cowboy. Files are stored under the plugin's data directory.

Summary

Functions

Read the full request body (up to 8MB default).

Read the full request body with custom options.

Save uploaded binary data to a file in the plugin's data directory.

Stream a file as the response body (chunked transfer).

Functions

read_body(Req)

-spec read_body(cowboy_req:req()) -> {ok, binary(), cowboy_req:req()}.

Read the full request body (up to 8MB default).

read_body(Req, Opts)

-spec read_body(cowboy_req:req(), map()) -> {ok, binary(), cowboy_req:req()}.

Read the full request body with custom options.

save_upload(PluginName, RelativePath, Data)

-spec save_upload(PluginName :: string() | binary(), RelativePath :: string(), Data :: binary()) ->
                     ok | {error, term()}.

Save uploaded binary data to a file in the plugin's data directory.

stream_file(Req0, FilePath, ContentType)

-spec stream_file(cowboy_req:req(), file:filename(), binary()) -> {ok, cowboy_req:req()}.

Stream a file as the response body (chunked transfer).