From 7cd13d22e0170e510fc51f7c39e47ae6768b8486 Mon Sep 17 00:00:00 2001 From: mpserafim <15836190+mpserafim@users.noreply.github.com> Date: Fri, 16 Dec 2022 08:09:13 -0300 Subject: [PATCH] docs(Uploader): Backend example with Perl/Mojolicious (#15106) * Backend example with Perl/Mojolicious Just adding a simple example of uploader backend with Perl/Mojolicious. * Update uploader.md Co-authored-by: Razvan Stoenescu --- docs/src/pages/vue-components/uploader.md | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/src/pages/vue-components/uploader.md b/docs/src/pages/vue-components/uploader.md index af679cf6310..f81fe1cd8c0 100644 --- a/docs/src/pages/vue-components/uploader.md +++ b/docs/src/pages/vue-components/uploader.md @@ -324,6 +324,37 @@ end isrunning(:webserver) || up() ``` +### Perl/Mojolicious + +``` +# Perl + +use Mojolicious::Lite -signatures; + +# CORS +app->hook(after_dispatch => sub { + my $c = shift; + $c->res->headers->header('Access-Control-Allow-Origin' => '*'); +}); +options '*' => sub ($c) { + $c->res->headers->header('Access-Control-Allow-Methods' => 'GET, OPTIONS, POST, DELETE, PUT'); + $c->res->headers->header('Access-Control-Allow-Headers' => 'Content-Type'); + $c->render(text => ''); +}; + +post '/upload' => sub ($c) { + my $uploads = $c->req->uploads('files'); + + foreach my $f (@{$uploads}) { + $f->move_to('/tmp/' . $f->filename); + } + + $c->render(text => 'Saved!'); +}; + +app->start; +``` + ## Supporting other services QUploader currently supports uploading through the HTTP(S) protocol. But you can extend the component to support other services as well. Like Firebase for example. Here's how you can do it.