You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
(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
;; Attachment class for saving metadata into RDBMS
(defclassimage (attachment) ()
(:metaclassmito:dao-table-class))
Saving
;; :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")