How can I upload a file using Catalyst?
Asked Answered
N

1

7

I am working on an internal web based application for storing and cataloging photos. How should I retrieve, and save these files to the server?

Note: I want to save the files to the file system, not to a database.
Similar to How can I handle HTTP file uploads?

Numbles answered 3/12, 2008 at 15:31 Comment(0)
D
15

Start with your familiar upload INPUT on your HTML form and ensure that the HTML form tag has the parameter enctype="multipart/form-data"

Your Catalyst::Request object ($c->request) provides two methods for accessing and manipulating the files.

Each file upload field will be instantiated as a Catalyst::Request::Upload object.

$c->request->upload will return the Upload objects in scalar or list form. $c->request->uploads will return a reference to hash of Upload objects.

The Upload object provides several method for saving and copying the files.

Check out the man pages that I've linked above.

Dias answered 3/12, 2008 at 16:43 Comment(4)
search.cpan.org/perldoc?Catalyst::Request search.cpan.org/perldoc?Catalyst::Request::UploadNumbles
is $c->request->uploads really returning a reference to a hash? When I look at the output in dumper it seems to be returning an array referenceSunder
@MatthewLock - either the docs are wrong, or you're misusing/misreading your dumper. The docs still say hashref.Dias
Yes uploads is returning a hashref if there's a single upload, but an arrayref or hashrefs if there are multiple uploads.Sunder

© 2022 - 2024 — McMap. All rights reserved.