[REBOL] Re: CGI and binary files
From: SunandaDH::aol::com at: 4-Jul-2005 12:28
Carl Read:
> Are there examples anywhere of how to upload binary files using a CGI
script?
> I'd need to be able to have the file keep its real name - ie. not be given
> the script name
This is the way REBOL.org handles it -- we allow files to be uploaded as part
of packages:
Step 1 - HTML
Should look something like this.....Your browser will prompt you to enter the
local file name
<form enctype="multipart/form-data" action="your-cgi-script.r">
<input type="file" name="file-name" size="50">
<input type="submit" name="update" value="update">
</form>
Step 2 -- multi-part decode
You need Andreas' magic code for handling multi-part binary data. Get it from
here:
http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-message.r?m=rmlKVSQ
Step 3 -- your CGI program
Needs to call Andreas' function to create an object, eg
post-data: read-cgi
cgi-object: construct decode-multipart-form-data
system/options/cgi/content-type
copy post-data
probe cgi-object ;;; to see what you got to work with.
You may need to fiddle around if your form has *optional* multi-part data as
Andreas' code will fail if none are present.
You'll also need to parse the uploaded file name to get the bit you want as
it'll be the fully-qualified path of the *local* name. Watch out for "\" in the
path -- IE can send them to you...other browsers correctly give you "/"s
Sunanda.