【问题标题】:Using PSGI, is it possible to change how uploaded files are named?使用 PSGI,是否可以更改上传文件的命名方式?
【发布时间】:2012-09-21 04:45:20
【问题描述】:

我有一个小型 PSGI 应用程序,它从表单中获取上传内容并将其传递给另一个脚本进行处理:

#!/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 ],
    ];
};

文件以/tmp/Fw8n6j0ICn.txt 之类的形式成功上传。问题是,处理依赖于文件在上传时被命名。

是否可以更改文件的上传方式,使其转到/tmp/Fw8n6j0ICn/original_name.txt

【问题讨论】:

    标签: perl plack psgi


    【解决方案1】:

    您可以通过$request 对象的filename 方法检索原始文件名,因此您基本上可以将$request->path 复制到您想要的任何位置并处理该文件。

    【讨论】:

      猜你喜欢
      • 2011-08-28
      • 2019-06-25
      • 1970-01-01
      • 1970-01-01
      • 2023-01-31
      • 1970-01-01
      • 2017-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多