Search code examples
perlwww-mechanize

WWW::Mechanize : How to upload file under different file name?


How to make WWW::Mechanize upload file under different file name?

I would like web server to see/record file name different from file name on my computer.


Solution

  • my $file = [
        'filename-on-disk.txt', # The file you'd like to upload.
        'filename-for-upload.txt', # The filename you'd like to give the web server.
        'Content-type' => 'text/plain' # Any other flags you'd like to add go here.
    ];
    
    $mech->post("http://example.com/upload.cgi", [
        'upload' => $file
    ]);
    

    Taken from: https://gist.github.com/gaurav/253111#file-file-upload-pl