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.
- Copyright: 2011-2015 Chad Phillips
- Author: Chad Phillips
|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.|
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.
- params Required. A table with the metadata necessary to create a new attachment
- 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.
A new attachment object.
attachment = luchia.core.attachment:new(params)
- params Required. A table with the metadata necessary to create a new attachment object.
Base64 encode the attachment file data.
The encoded data.
encoded_data = attachment:base64_encode_file()
Load the attachment file data.
The file data.
data = attachment:load_file()
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.
- server Required. The server object to prepare the request for.