3

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.

AnFi
  • 10,493
  • 3
  • 23
  • 47
  • I don't know if there is an easy way to do this except by creating your own custom request. – amon Sep 08 '13 at 15:31

2 Answers2

4
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

emazep
  • 483
  • 5
  • 6
0

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.
Joseph R.
  • 785
  • 4
  • 11
  • I would prefer a solution without even temporary changes in the file system. I hope a cleaner alternative to your suggestion will emerge :-) – AnFi Sep 08 '13 at 20:27