Yancy::Plugin::File - Manage file uploads, attachments, and other assets
# Write a file
$c->yancy->file->write( $c->param( 'upload' ) );
Note: This module is EXPERIMENTAL and its API may change before Yancy v2.000 is released.
This plugin manages file uploads. Files are stored in the file_root by
This plugin API is meant to be subclassed by other asset storage mechanisms such as Hadoop or Amazon S3.
Files are NOT immediately deleted after they are no longer needed. Instead, a "cleanup" method exists to periodically clean up any files that are not referenced. You should schedule this to run daily or weekly in cron:
# Clean up files every week
0 0 * * 0 ./myapp.pl eval 'app->yancy->file->cleanup( app->yancy->backend, app->yancy->schema )'
$url_path = $c->yancy->file->write( $upload );
$url_path = $c->yancy->file->write( $name, $asset );
Write a file into storage. $upload is a Mojo::Upload object. $name is a filename and $asset is a Mojo::Asset object. Returns the URL of the uploaded file.
$app->yancy->file->cleanup( $app->yancy->backend );
$app->yancy->file->cleanup( $app->yancy->backend, $app->yancy->schema );
Clean up any files that do not exist in the given backend. Call this daily or weekly to remove files that aren't needed anymore.
This plugin has the following configuration options.
The root path to store files. Defaults to public/uploads in the application's home directory.
The URL used to reach the file_root. Defaults to /uploads.
The name to use for the helper. Defaults to file (creating a yancy.file helper). Change this to add multiple file plugins.
Doug Bell <email@example.com>
This software is copyright (c) 2021 by Doug Bell.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Yancy, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.