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

[REBOL] Re: How to file upload via http?

From: andreas:bolka:gmx at: 22-Aug-2002 23:04

Thursday, August 22, 2002, 5:45:09 AM, Jason wrote:
> Does anyone have an example of a rebol server-side script to handle file upload > via http ?
I've a 'decode-multipart-form-data avail (as I guess that you are interested in this becaus of vanillla, this will be distributed with vanilla 0.5.2) I guess for a simple savefile CGI this will be a bit harder to use than %POST.r, but I think decode-multipart-form-data is a cleaner approach - let me know what you think! Here it is: -- snip -- REBOL [ Title: "decode-multipart-form-data" Authors: [ "Andreas Bolka" ] Contributors: [ ] Date: 2002-06-18 Version: 1.1 Purpose: { Decodes POST-data encoded as "multipart/form-data" as defined by RFC 2388. The output is compatible to 'decode-cgi wherever possible. So the output contains a list of set-word's and values, one pair for each data field. example: [ field1: "foo" field2: "bar" ] If the content type of one part of the form-data is not equal to text/plain, then the value of the respective mime-part is an object! with the following attribs: filename, type, content. example: [ field1: "foo" field2: make object! [ filename: "user.xml" type: "text/xml" content: "<?xml version='1.0'><user />" ] ] } ] decode-multipart-form-data: func [ p-content-type p-post-data /local list ct pd bd delim-beg delim-end mime-part ] [ list: copy [] if not found? find p-content-type "multipart/form-data" [ return list ] ct: copy p-content-type pd: copy p-post-data bd: join "--" copy find/tail ct "boundary=" delim-beg: join crlf crlf delim-end: rejoin [ crlf bd ] mime-part: [ ( ct-dispo: content: none ct-type: "text/plain" ) thru bd thru "content-disposition: " copy ct-dispo to crlf opt [ thru "content-type: " copy ct-type to crlf ] thru delim-beg copy content to delim-end ( handle-mime-part ct-dispo ct-type content ) ] handle-mime-part: func [ p-ct-dispo p-ct-type p-content /local fieldname ] [ p-ct-dispo: parse p-ct-dispo {;="} fieldname: select p-ct-dispo "name" append list to-set-word fieldname either found? find p-ct-type "text/plain" [ append list content ] [ append list make object! [ filename: select p-ct-dispo "filename" type: copy p-ct-type content: either none? p-content [ none ] [ copy p-content ] ] ] ] use [ ct-dispo ct-type content ] [ parse/all pd [ some mime-part ] ] list ] -- snap -- -- Best regards, Andreas mailto:[andreas--bolka--gmx--net]