Class luchia.core.attachment

Core attachment handler class.

Implements the methods necessary to handle attachments. Note that for most cases, the attachment handling methods in luchia.document should be used; this module provides the core functionality that those higher-level methods use.

See the core.attachment.lua example for more detail.

Info:

  • Copyright: 2011-2015 Chad Phillips
  • Author: Chad Phillips

Methods

luchia.core.attachment:new(params) Creates a new core attachment handler.
luchia.core.attachment:base64_encode_file() Base64 encode the attachment file data.
luchia.core.attachment:load_file() Load the attachment file data.
luchia.core.attachment:prepare_request_data(server) Prepare attachment for a server request.


Methods

luchia.core.attachment:new(params)
Creates a new core attachment handler.

In order to add an attachment to a document, an attachment object must be created, then attached to the document, as seen in luchia.core.document:add_attachment, luchia.document:add_standalone_attachment, and luchia.document:add_inline_attachment.

In order to send a standalone attachment via the core server methods, an attachment object must be created, and passed to the 'data' parameter of luchia.core.server:request.

Parameters:

  • params Required. A table with the metadata necessary to create a new attachment object.
    • file_path Required. The path to the file to add as an attachment. Relative paths can be used, but must have a path component, eg. "./myfile" or "/tmp/attachment.txt".
    • content_type Required. The mime content type of the attachment, eg. "text/plain".
    • file_name Optional. The name of the attachment as stored in couchdb. If not provided, then the base name of file_path will be used.
    • custom_loader_function Optional. By default, files are loaded via the load_file method in this class. Use this to specify an alternate loader function.

Returns:

    A new attachment object.

Usage:

    attachment = luchia.core.attachment:new(params)
luchia.core.attachment:base64_encode_file()
Base64 encode the attachment file data.

Returns:

    The encoded data.

Usage:

    encoded_data = attachment:base64_encode_file()
luchia.core.attachment:load_file()
Load the attachment file data.

Returns:

    The file data.

Usage:

    data = attachment:load_file()
luchia.core.attachment:prepare_request_data(server)
Prepare attachment for a server request.

This method is called by luchia.core.server:prepare_request_data to allow the attachment object to properly prepare the data for a server request.

Parameters:

  • server Required. The server object to prepare the request for.

Usage:

    attachment:prepare_request_data(server)
generated by LDoc 1.4.3 Last updated 2016-01-14 11:22:48