Replies: 2 comments 8 replies
-
post '/upload' => sub ($c) {
for ($c->req->uploads('the-field-name-from-your-mltipart/formdata-form') ){ # <- this is wrong see below
$_->move_to( sprintf '/var/lib/myapp/upload/%s', $_->filename)
}
}; |
Beta Was this translation helpful? Give feedback.
7 replies
-
|
Thanks everybody, I think the main issue was just getting confused by the documentation. I was looking at the request and content documentation but not the message documentation where the "uploads" method is mentioned. Once I found that it got a lot easier. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The context is I created a site 15 years ago using Mojolicious, ran into problems, and about 10 years ago I converted the site to use straight Plack with a lot of custom code. I've always meant to get back to using Mojolicious and occasionally I have time to work on that. The biggest obstacle for me is the documentation, and I know saying that ruffles a lot of feathers, but I pretty much always have to google answers about Mojolicious to find them on places like Stack Overflow. However I have run into a problem that I can't find an answer to googling so here I am.
The problem is I want to upload a file and the Mojolicious Tutorial page suggests this should be easy, with the content of the file included along with the other parameters I am submitting. However that is not the case and the name of the file type HTML form input is not included in the parameters. Below is code that I wrote 15 years ago to get around this problem, which loads a hash keyed by file name with the uploaded file(s) content. It does not work because I assume due to changes with Mojolicous internals over the last 15 years. I expect to have to just update this code, but before I do that I would like to ask if there is a better way. At this point in the code I have no idea what the input name might be, I just want to grab any files uploaded. If the file contents were included as a parameter then I wouldn't need this code at all.
`
`
Beta Was this translation helpful? Give feedback.
All reactions