Question

I have a small PSGI app which takes an upload from a form and passes it off to another script for processing:

#!/usr/bin/perl

use strict;
use warnings;

use Plack::Request;
use HTTPStatusCode;

my $app = sub {
    my $req = Plack::Request->new(shift);

    my $content;
    if (keys %{$req->uploads}) {
        $content = do_something_with_upload($req);
    } else {
        $content = display_form();
    }

    return [
        HTTPStatusCode->SUCCESS,
        [ 'Content-type', 'text/html' ],
        [ $content ],
    ];
};

The file gets uploaded successfully as something like /tmp/Fw8n6j0ICn.txt. The problem is, the processing relies on the file being named as it was when uploaded.

Is it possible to change how files are uploaded so they go to /tmp/Fw8n6j0ICn/original_name.txt ?

Was it helpful?

Solution

You can retrieve the original filename via filename method of $request object, so you can basically copy the $request->path to whatever you desire and process that file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top