Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the mito-attachment Reference Manual, version 0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Aug 15 05:23:45 2022 GMT+0.
Next: Systems, Previous: The mito-attachment Reference Manual, Up: The mito-attachment Reference Manual [Contents][Index]
The place to store files would be a problem when you intend to write a web application which allows file-uploading. These days, AWS S3 is a common place to store/serve files, however, it's not easy to manage like RDBMS.
Mito-attachment provides a Mito mixin class for managing files outside of RDBMS. It stores files before mito:save-dao
and deletes them before mito:delete-dao
.
Besides, the backend storage can be replaced easily. This makes it easy that using cloud storage services for production environment and using local filesystem for development environment.
(defvar *appenv* (uiop:getenv "APP_ENV"))
;; Setup storage class
(setf *storage*
(if (string= *appenv* "production")
;; Store files in AWS S3 for production environment
(make-instance 's3-storage
:bucket "mito-attachment-example"
:endpoint "s3-ap-northeast-1.amazonaws.com"
:access-key (uiop:getenv "AWS_ACCESS_KEY")
:secret-key (uiop:getenv "AWS_SECRET_KEY"))
;; Store files in local filesystem for development environment
(make-instance 'disk-storage
:bucket "mito-attachment-example"
:directory #P"/tmp/attachment/")))
;; Attachment class for saving metadata into RDBMS
(defclass image (attachment) ()
(:metaclass mito:dao-table-class))
;; :content can be specified as a pathname or a stream.
(mito:create-dao 'image :content #P"uploaded-file.png")
;; Override the file content-type
(mito:create-dao 'image :content #P"uploaded-file.png" :content-type "image/png")
;; Use an original file-key
(mito:create-dao 'image :content #P"uploaded-file.png" :file-key "image.png")
(let ((file (mito:find-dao 'image :id 1)))
(file-url file))
;-> ;; SELECT * FROM "image" WHERE ("id" = ?) LIMIT 1 (1) [1 row] | MITO.DB:RETRIEVE-BY-SQL
;=> "/mito-attachment-example/3616D80112884799B272DC962F4BBF97.jpg"
See example.lisp for getting the full example. It's a Lack web application which allows users to upload image files.
(ql:quickload :mito-attachment)
Copyright (c) 2016 Eitaro Fukamachi (e.arrows@gmail.com)
Licensed under the LLGPL License.
Next: Modules, Previous: Introduction, Up: The mito-attachment Reference Manual [Contents][Index]
The main system appears first, followed by any subsystem dependency.
Mito mixin class for file management
Eitaro Fukamachi
LLGPL
# mito-attachment
The place to store files would be a problem when you intend to write a web application which allows file-uploading. These days, AWS S3 is a common place to store/serve files, however, it’s not easy to manage like RDBMS.
Mito-attachment provides a Mito mixin class for managing files outside of RDBMS. It stores files before ‘mito:save-dao‘ and deletes them before ‘mito:delete-dao‘.
Besides, the backend storage can be replaced easily. This makes it easy that using cloud storage services for production environment and using local filesystem for development environment.
## Usage
### Setting up the storage
“‘common-lisp
(defvar *appenv* (uiop:getenv "APP_ENV"))
;; Setup storage class
(setf *storage*
(if (string= *appenv* "production")
;; Store files in AWS S3 for production environment
(make-instance ’s3-storage
:bucket "mito-attachment-example"
:endpoint "s3-ap-northeast-1.amazonaws.com"
:access-key (uiop:getenv "AWS_ACCESS_KEY")
:secret-key (uiop:getenv "AWS_SECRET_KEY"))
;; Store files in local filesystem for development environment
(make-instance ’disk-storage
:bucket "mito-attachment-example"
:directory #P"/tmp/attachment/")))
“‘
### Defining an attachment Mito class
“‘common-lisp
;; Attachment class for saving metadata into RDBMS
(defclass image (attachment) ()
(:metaclass mito:dao-table-class))
“‘
### Saving
“‘common-lisp
;; :content can be specified as a pathname or a stream.
(mito:create-dao ’image :content #P"uploaded-file.png")
;; Override the file content-type
(mito:create-dao ’image :content #P"uploaded-file.png" :content-type "image/png")
;; Use an original file-key
(mito:create-dao ’image :content #P"uploaded-file.png" :file-key "image.png")
“‘
### Getting the URL
“‘common-lisp
(let ((file (mito:find-dao ’image :id 1)))
(file-url file))
;-> ;; SELECT * FROM "image" WHERE ("id" = ?) LIMIT 1 (1) [1 row] | MITO.DB:RETRIEVE-BY-SQL
;=> "/mito-attachment-example/3616D80112884799B272DC962F4BBF97.jpg"
“‘
See [example.lisp](example.lisp) for getting the full example. It’s a Lack web application which allows users to upload image files.
## Installation
“‘common-lisp
(ql:quickload :mito-attachment)
“‘
## See Also
* [Mito](https://github.com/fukamachi/mito)
* [Clipper](https://github.com/Rudolph-Miller/clipper) for Integral
## Author
* Eitaro Fukamachi (e.arrows@gmail.com)
## Copyright
Copyright (c) 2016 Eitaro Fukamachi (e.arrows@gmail.com)
## License
Licensed under the LLGPL License.
0.1
src (module).
Next: Files, Previous: Systems, Up: The mito-attachment Reference Manual [Contents][Index]
Modules are listed depth-first from the system components tree.
Next: mito-attachment/src/storage-components, Previous: Modules, Up: Modules [Contents][Index]
mito-attachment (system).
Previous: mito-attachment/src, Up: Modules [Contents][Index]
src (module).
Next: Packages, Previous: Modules, Up: The mito-attachment Reference Manual [Contents][Index]
Files are sorted by type and then listed depth-first from the systems components trees.
Next: mito-attachment/src/mito-attachment.lisp, Previous: Lisp, Up: Lisp [Contents][Index]
mito-attachment (system).
Next: mito-attachment/src/mixin.lisp, Previous: mito-attachment/mito-attachment.asd, Up: Lisp [Contents][Index]
src (module).
Next: mito-attachment/src/storage.lisp, Previous: mito-attachment/src/mito-attachment.lisp, Up: Lisp [Contents][Index]
src (module).
initialize-with-content (function).
Next: mito-attachment/src/storage-components/disk.lisp, Previous: mito-attachment/src/mixin.lisp, Up: Lisp [Contents][Index]
src (module).
Next: mito-attachment/src/storage-components/s3.lisp, Previous: mito-attachment/src/storage.lisp, Up: Lisp [Contents][Index]
storage-components (module).
Next: mito-attachment/src/util.lisp, Previous: mito-attachment/src/storage-components/disk.lisp, Up: Lisp [Contents][Index]
storage-components (module).
Previous: mito-attachment/src/storage-components/s3.lisp, Up: Lisp [Contents][Index]
src (module).
slurp-stream (function).
Next: Definitions, Previous: Files, Up: The mito-attachment Reference Manual [Contents][Index]
Packages are listed by definition order.
Next: mito.attachment.storage, Previous: Packages, Up: Packages [Contents][Index]
common-lisp.
slurp-stream (function).
Next: mito.attachment.storage.disk, Previous: mito-attachment.util, Up: Packages [Contents][Index]
common-lisp.
Next: mito-attachment-asd, Previous: mito.attachment.storage, Up: Packages [Contents][Index]
Next: mito-attachment, Previous: mito.attachment.storage.disk, Up: Packages [Contents][Index]
Next: mito.attachment.mixin, Previous: mito-attachment-asd, Up: Packages [Contents][Index]
mito.attachment
common-lisp.
Next: mito.attachment.storage.s3, Previous: mito-attachment, Up: Packages [Contents][Index]
common-lisp.
initialize-with-content (function).
Previous: mito.attachment.mixin, Up: Packages [Contents][Index]
Next: Indexes, Previous: Packages, Up: The mito-attachment Reference Manual [Contents][Index]
Definitions are sorted by export status, category, package, and then by lexicographic order.
Next: Internals, Previous: Definitions, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Public Interface, Up: Public Interface [Contents][Index]
Next: Generic functions, Previous: Special variables, Up: Public Interface [Contents][Index]
Next: Standalone methods, Previous: Ordinary functions, Up: Public Interface [Contents][Index]
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
Next: Classes, Previous: Generic functions, Up: Public Interface [Contents][Index]
lack.component.
mito.dao.
mito.dao.
Previous: Standalone methods, Up: Public Interface [Contents][Index]
common-lisp.
:directory
:mount-path-prefix
Initarg | Value |
---|---|
:endpoint | *s3-endpoint* |
:access-key
:secret-key
:session-token
zs3:*s3-region*
:region
Previous: Public Interface, Up: Definitions [Contents][Index]
Next: Ordinary functions, Previous: Internals, Up: Internals [Contents][Index]
Next: Generic functions, Previous: Macros, Up: Internals [Contents][Index]
Previous: Ordinary functions, Up: Internals [Contents][Index]
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
automatically generated reader method
automatically generated writer method
Previous: Definitions, Up: The mito-attachment Reference Manual [Contents][Index]
Jump to: | (
C D F G I M S W |
---|
Jump to: | (
C D F G I M S W |
---|
Next: Data types, Previous: Functions, Up: Indexes [Contents][Index]
Jump to: | *
A B C D E F M P R S |
---|
Jump to: | *
A B C D E F M P R S |
---|
Jump to: | A C D F M P S U |
---|
Jump to: | A C D F M P S U |
---|