Subject: | [HTTP::Request::Common] can't specify filename and headers when not uploading from file |
The HTTP::Request::Common documentation is unclear on how to use the Form-based File Upload method without using a file (to upload content directly). After reading the source it turns out that if one choose to upload content directly it's impossible to specify file name and headers (content-type,...). Here is a patch against 1.23. I don't know if it's The Right Way(tm) to do it but it works and it doesn't seem to break anything while being as small as possible. If you choose not to include this patch in the next release, please at least make the documentation more accurate on how to do a RFC 1867-style upload without using a file.
Here are informations asked on the form but I don't think it's relevant:
libwww-perl 5.800-1
Perl v5.8.4 i386-linux-thread-multi
Linux 2.4.26-1-k7
(all these things come from official Debian Sarge packages)
Thanks,
Adrien "Krunch" Kunysz
1a2
> # $Id: Common.pm,v 1.24 2004/09/08 13:37:00 Adrien Kunysz Exp $
142c143,144
< if ($file) {
---
> local $SIG{'__WARN__'} = sub {}; # make stat() shut up
> if (-r $file) {
160a163,165
> elsif ($file) {
> $content = $file;
> }
377,382c382,389
< This file will be read and its content placed in the request. The
< routine will croak if the file can't be opened. Use an C<undef> as $file
< value if you want to specify the content directly. The $filename is
< the filename to report in the request. If this value is undefined,
< then the basename of the $file will be used. You can specify an empty
< string as $filename if you don't want any filename in the request.
---
> This file will be read and its content placed in the request. If $file
> isn't readable (! -r $file) it will be taken as the data to upload.
> The routine will C<Croak> if the file is readable but can't be opened.
> Use an C<undef> as $file value if you want to specify the content
> directly. The $filename is the filename to report in the request.
> If this value is undefined, then the basename of the $file will be
> used. You can specify an empty string as $filename if you don't want
> any filename in the request.