AnFi
AnFi

Reputation: 10913

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.

Upvotes: 3

Views: 1026

Answers (2)

emazep
emazep

Reputation: 489

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

Upvotes: 4

Joseph R.
Joseph R.

Reputation: 805

You can use a hard link:

link "file_name_on_your_computer","desired_new_name";
# Code to upload the newly created link
unlink "desired_new_name";

Notes

  • You need not worry about disk space usage if you're using a large file: the file is not duplicated, the hard link is simply a new name for the same inode.
  • This solution is limited to just those filesystems that support hard links. If you're on Windows, this may end up creating and uploading only a shortcut to your original file.

Upvotes: 0

Related Questions