HTTP file upload v perlu

Honza Pazdziora adelton na informatics.muni.cz
Čtvrtek Červen 5 22:38:31 MEST 2003


On Thu, Jun 05, 2003 at 08:54:16PM +0200, Jan Kasprzak wrote:
> 
> 	jak byste udelali upload souboru pres HTTP v Perlu? Myslim tim
> tu stranu, co posila soubor (tak jako kdyby byl z HTML formulare
> z polozky INPUT TYPE=file), nikoliv snad prijem toho souboru na druhe
> strane.
> 
> 	Zrejme to jde pres LWP::UserAgent nebo neco takoveho, ale zatim
> jsem nezjistil jak.

Upload souboru pres HTTP je normalni POST, akorat s typem
multipart/form-data. Cili je to zalezitost obsahu (tvaru) toho
HTTP::Requestu, ktery budes tim LWP::UserAgentem posilat. Ale
samozrejme to muzes poslat i cimkoli jinym.

Dokumentace HTTP::Request::Common mj. rika:

           The POST method also supports the "multipart/form-data" content
           used for Form-based File Upload as specified in RFC 1867.  You
           trigger this content format by specifying a content type of
           'form-data' as one of the request headers.  If one of the values in
           the $form_ref is an array reference, then it is treated as a file
           part specification with the following interpretation:

             [ $file, $filename, Header => Value... ]

           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
           [...]

Je tam i pekny priklad na to, jak konkretni soubor poslat.
	
-- 
------------------------------------------------------------------------
 Honza Pazdziora | adelton na fi.muni.cz | http://www.fi.muni.cz/~adelton/
 .project: Perl, mod_perl, DBI, Oracle, auth. WWW servers, XML/XSL, ...
		Only self-confident people can be simple.


Další informace o konferenci Perl