Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: upload files via http with Rebol?

From: SunandaDH:aol at: 18-Dec-2004 11:49

> Does anyone know where I can find out how to allow users to upload files > via their web browsers and save them with Rebol?
I went round in circles working this out at the beginning of this year. This is what I ended up with. STEP 1 -- get read-cgi You may have this function already -- you'll be using it for non-multipart files. If not, it's here: STEP 2 -- get code to decode multipart CGI data Luckily, Andreas did the hard part for us, and published it on the Mailing List. Available from: with some further discussion here: STEP 3: The HTML As with all other CGI languages, you need some HTML. Something like this for a simple page that has a single file to upload (Andreas' code works happily with multiple files on the same page). You'll need to add the name of your CGI program in the action tag <form enctype="multipart/form-data" action="...your cgi program..." method="post"> <div> <input type="text" name="non-mp1" size="20"> <input type="file" name="mp1" size="50"> <input type="submit" alt="update button" name="update" value="update"> </div> </form> STEP 4 -- Process it in a CGI program This code is somewhat convoluted as it covers the case where the input data does not contain any multi-part fields. (It's written that way so a single CGI program can both put out a blank form and process the results from it). Your code can be simpler if the CGI is used only to read a page with multi-part data. post-data: read-cgi error? try [cgi-object: construct decode-cgi copy post-data] error? try [cgi-object: construct cons-utils/decode-multipart-form-data system/options/cgi/content-type copy post-data ] if error? try [cgi-object/non-mp1] [ error? try [cgi-object: construct decode-cgi copy post-data]] ;; You can now do things with the uploaded file, eg write/binary %saved-file cgi-object/mp1 You can see the end results of this here.... ds-demo1-package.r .....the page is listing mainly JPGs that were uploaded this this code. Sunanda.