Re: Urgent Help needed with Post method file upload
Eric Langheinrich [EMAIL PROTECTED] writes: Okay, so in the useragent, I pass the filename as an array reference [$task_add_datakey] what actually gets the contents of the file and posts them? The form_data() function in the HTTP::Request::Common module reads the content. Is there another way to do it? I would recommend that you first figure out what the problem is before you start looking for another way. As I said, the file data is already read in binary mode, so that's certainly not the problem. Am I better off opening a raw socket and writing the headers and the data myself? My concern is that to get the raw binary to write properly in the first place, I had to run binmode FILEHANDLE :raw on the file handle that I was writing to. From what I've read, I would need to do that on the read of the file contents as well in order to properly get the data. Is the library setup to handle raw binary data? Regards, Gisle
Re: Urgent Help needed with Post method file upload
Eric Langheinrich [EMAIL PROTECTED] writes: I'm not able to inspect the file on the host. I get back and XML string with a result. Try to print the request that POST() returns above to see if you can spot what is wrong. $req = POST($baseurl, ); print $req-as_string; $res = $ua-request($req); The response from the server is basic header information and an XML string. I have the following to receive the response: What I suggested above was to inspect the request before it is sent, since you seemed to think that it was not set up properly. Regards, Gisle
Re: Urgent Help needed with Post method file upload
What I suggested above was to inspect the request before it is sent, since you seemed to think that it was not set up properly. At this point, I'm pretty sure the request is perfect! Thank you for the help. I taking that function out of the overall script and running it byitself, seems to work fine. The problem must be all mine, although for the life of me I can't seem to figure out what it would be. When I run the function in it's own script not as a function, the file size appears to transmit correctly. When the function as a function within the bigger script the size is always wrong. I've done character by character comparisons between the function and it's stand alone mode and can't seem to find any real difference. Really quite baffling at this point. Thank you again for all of the help. You definitely pointed me in the right direction.
Re: Urgent Help needed with Post method file upload
Eric Langheinrich [EMAIL PROTECTED] writes: I'm attempting to post a file in a multipart/form-data post using LWP::UserAgent and the following command string: my $response = $ua-request(POST $baseurl, Content_Type = 'form-data', Content = [ request_params = $task_add_postkey, datafile = [$task_add_datakey] ]); Where $task_add_postkey is a set of key value pairs of form data, and $task_add_datakey is the full path file name of a file containing binary data. The post seems to work fine with the exception of the 48 byte file I am sending, is received as 61 bytes on the server. I'm assuming it has something to do with how the file is being parsed. Are you able to inspect the file received on the server side to figure out what is actually different? Is there a better way to put together a multipart post? Am I missing something obvious? Is there a way to control the file parser so that the data is handled as raw binary data? The file should already be included as binary. There is no file parser involved. Any ideas Try to print the request that POST() returns above to see if you can spot what is wrong. $req = POST($baseurl, ); print $req-as_string; $res = $ua-request($req); ... Regards, Gisle
Re: Urgent Help needed with Post method file upload
Okay, so in the useragent, I pass the filename as an array reference [$task_add_datakey] what actually gets the contents of the file and posts them? Is there another way to do it? Am I better off opening a raw socket and writing the headers and the data myself? My concern is that to get the raw binary to write properly in the first place, I had to run binmode FILEHANDLE :raw on the file handle that I was writing to. From what I've read, I would need to do that on the read of the file contents as well in order to properly get the data. Is the library setup to handle raw binary data? - Original Message - From: Gisle Aas [EMAIL PROTECTED] To: Eric Langheinrich [EMAIL PROTECTED] Cc: libwww@perl.org Sent: Saturday, August 13, 2005 12:05 PM Subject: Re: Urgent Help needed with Post method file upload Eric Langheinrich [EMAIL PROTECTED] writes: I'm attempting to post a file in a multipart/form-data post using LWP::UserAgent and the following command string: my $response = $ua-request(POST $baseurl, Content_Type = 'form-data', Content = [ request_params = $task_add_postkey, datafile = [$task_add_datakey] ]); Where $task_add_postkey is a set of key value pairs of form data, and $task_add_datakey is the full path file name of a file containing binary data. The post seems to work fine with the exception of the 48 byte file I am sending, is received as 61 bytes on the server. I'm assuming it has something to do with how the file is being parsed. Are you able to inspect the file received on the server side to figure out what is actually different? Is there a better way to put together a multipart post? Am I missing something obvious? Is there a way to control the file parser so that the data is handled as raw binary data? The file should already be included as binary. There is no file parser involved. Any ideas Try to print the request that POST() returns above to see if you can spot what is wrong. $req = POST($baseurl, ); print $req-as_string; $res = $ua-request($req); ... Regards, Gisle
Re: Urgent Help needed with Post method file upload
I reread the docs and saw this: [ $file, $filename, Header = Value... ] [ undef, $filename, Header = Value,..., Content = $content ]The first value in the array ($file) is the name of a file to open. 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 undef as $file value if you want to specify the content directly with a Content header. 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 want to suppress sending the filename when you provide a $file value. And updated my post request to look like this: my $response = $ua-request(POST $baseurl, Content_Type = 'form-data', Content = [ request_params = $task_add_postkey, datafile = [ undef, 'datafile', Content-Type = 'application/octet-stream', Content = $filedata ] ]); When I run the script, I get: Bareword Content not allowed while strict subs in use at regcompliance.pl line 438 Any ideas? Thank you, Eric
Re: Urgent Help needed with Post method file upload
Le samedi 13 août 2005 à 16:40, Eric Langheinrich écrivait: I reread the docs and saw this: snip And updated my post request to look like this: my $response = $ua-request(POST $baseurl, Content_Type = 'form-data', Content = [ request_params = $task_add_postkey, datafile = [ undef, 'datafile', Content-Type = 'application/octet-stream', Content = $filedata ] ]); When I run the script, I get: Bareword Content not allowed while strict subs in use at regcompliance.pl line 438 Any ideas? s/Content-Type/Content_Type/ -- Philippe BooK Bruhat In the contest between simplicity and silence, silence hasn't got a prayer. (Moral from Groo The Wanderer #15 (Epic))