Re: CGI.pm and Large File Transfers
by iburrell (Chaplain) on Mar 15, 2004 at 22:08 UTC
|
| [reply] |
|
The more I think about this challenge, the less I think the http solution will work and still be reliable (http certainly was not designed for it).
As for upload_hook, I found it in the CGI.pm page on CPAN.org:
You can set up a callback that will be called whenever a file upload is being read during the form processing. This is much like the UPLOAD_HOOK facility available in Apache::Request, with the exception that the first argument to the callback is an Apache::Upload object, here it's the remote filename.
$q = CGI->new();
$q->upload_hook(\&hook,$data);
sub hook
{
my ($filename, $buffer, $bytes_read, $data) = @_;
print "Read $bytes_read bytes of $filename\n";
}
If using the function-oriented interface, call the CGI::upload_hook() method before calling param() or any other CGI functions:
CGI::upload_hook(\&hook,$data);
This method is not exported by default. You will have to import it explicitly if you wish to use it without the CGI:: prefix.
| [reply] [d/l] [select] |
|
HTTP is just as reliable and fast as FTP. More reliable since there is only one connection instead of the separate data connection with FTP so less firewall worries. And you don't have to worry about a separate server with different authentication.
Also, if you don't need other form fields (including the filename), then you can do a POST with the file content as the body. The receiving CGI would not use CGI.pm to parse the upload but read the body directly and save it to disk. The filename would have to be constructed by some other mechanism.
| [reply] |
Re: CGI.pm and Large File Transfers
by hardburn (Abbot) on Mar 15, 2004 at 21:52 UTC
|
CGI.pm saves it to a temporary file. Note, though, that allowing anyone to upload a file of any size like this is a security problem (CGI.pm's documentation on file transfers goes over this).
HTTP wasn't designed with file uploading in mind, and I suggest finding a different solution.
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
| [reply] [d/l] |
|
Thanks for the input. I think you are correct. Have any suggestions? I have a few ideas, but its always good to hear more options!
thanks for the response!
| [reply] |
Re: CGI.pm and Large File Transfers
by Joost (Canon) on Mar 15, 2004 at 22:43 UTC
|
Q1 - As pointed out above, CGI.pm saves uploads to a temporary file so it can handle any file size as long as you have disk space left. I've handled over 600 Mb files with it without any problems except buggy Internet Explorers :-)
Q2 - I never noticed that callback, but you probably won't be able to do the notification very efficiently in a CGI. What I do in situations like this is: on form submit I show an animated gif indicating the upload is taking place:
<form ... onsubmit="document.images['imagename'].src='animation.gif';"
+>
....
</form>
Or something like it (can't remember the excact javascript now)
It's a lot easier and looks almost as good :-)
Joost.
| [reply] [d/l] |
Re: CGI.pm and Large File Transfers
by tachyon (Chancellor) on Mar 15, 2004 at 23:46 UTC
|
Lots of options other than CGI directly. You could use ftp, sftp, scp, ssh protected ftp, rsync, wget. You could use server pull rather than client push, letting the remote server pull the file from your local box. You could just do it with sockets. There are lots of ways to transfer files.
Assuming that this is a regular upload you could just put the data into a browsable location locally (assuming you have a web server onsite), protect it with a .htaccess file and just set a cron job to get it whenever it suits using wget.
| [reply] |
Re: CGI.pm and Large File Transfers
by Anonymous Monk on Mar 16, 2004 at 05:25 UTC
|
Uploading a 100 MB file through HTTP is sure to take a long time. Downloading a 100 MB is bad enough, but most people have a MUCH lower upload bandwidth than they do a download one. Chances are most likely that the web server you're working on times out HTTP connections after a certain period of time (my version of Apache has a default 300 second limit). If you're using Apache, you can change this timeoput limit so that the upload won't be cancelled, but I can't imagine the number of minutes or hours a 100 MB upload would take. I'd definitely look for another approach to this.
| [reply] |
Re: CGI.pm and Large File Transfers
by Avox (Sexton) on Mar 16, 2004 at 19:37 UTC
|
Thanks everyone. I think i'm going to use http to start a ftp transaction on the server. It will probably be a bit cleaner that way. Thanks so much for everyone's help! | [reply] |