The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Yancy::Plugin::File - Manage file uploads, attachments, and other assets

VERSION

version 1.080

SYNOPSIS

    # Write a file
    $c->yancy->file->write( $c->param( 'upload' ) );

DESCRIPTION

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.

Cleanup

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 )'

METHODS

write

    $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.

cleanup

    $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.

CONFIGURATION

This plugin has the following configuration options.

file_root

The root path to store files. Defaults to public/uploads in the application's home directory.

url_root

The URL used to reach the file_root. Defaults to /uploads.

moniker

The name to use for the helper. Defaults to file (creating a yancy.file helper). Change this to add multiple file plugins.

SEE ALSO

Yancy

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

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.