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

need example of upload

 [1/11] from: pat:scotto:wanadoo at: 10-Sep-2003 20:12


hello, I look for an very basic example of http upload to post big file via http. just need html (easy;-) and upload.r I search that without succes on the net , all seem bugged . I use rebol command 2.0 on linux . thank you ... patrick ...

 [2/11] from: andrew:martin:colenso:school at: 11-Sep-2003 13:36


Patrick wrote:
> I look for an very basic example of http upload to post big file via
http.
> just need html (easy;-) and upload.r
Could you give an example as I don't know what you mean? Do you want an example of the HTML to be shown in a browser for a user to upload a file through their browser to the site? Or do you want a Rebol script to upload a big file in response to the above page? Or am I confused? :) Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [3/11] from: tim:johnsons-web at: 10-Sep-2003 20:27


Patrick: Are you perhaps referring to the RFC 2388 protocol? If so, there is an (non-functional) example of a form using that protocol at http://www.johnsons-web.com/upload.html. Andreas Bolka <[andreas--bolka--gmx--net]> has written a rebol function useful for handling that protocol. It is called 'decode-multipart and if Andres isn't monitoring this thread, I would be happy to provide it. tim * Andrew Martin <[andrew--martin--colenso--school--nz]> [030910 18:34]:
> Patrick wrote: > > I look for an very basic example of http upload to post big file via > http. > > just need html (easy;-) and upload.r > > Could you give an example as I don't know what you mean? <snip>
-- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

 [4/11] from: pat::scotto::wanadoo::fr at: 11-Sep-2003 18:20


Andrew Martin a écrit:
>Patrick wrote: >>I look for an very basic example of http upload to post big file via
<<quoted lines omitted: 10>>
>above page? >Or am I confused? :)
no sorry my english is awfull, but i need only the rebol script ;-) I think , I know write a html file to upload a file like that *------* <form method="post" enctype="multipart/form-data" action="upload.r"> <input type="hidden" name="path" value="my_path"> <input type="file" name="thefile" > <br><input type="submit" name="taskSubmit" value="writeThat">To Submit</form> *------* just need a correct script rebol to understand. patrick ...

 [5/11] from: carl:rebol at: 11-Sep-2003 19:41


HTTP post example. Includes both sides (uploader and web server script). Short and sweet: http://www.rebol.net/cookbook/recipes/0026.html

 [6/11] from: andreas:bolka:gmx at: 12-Sep-2003 17:26


Friday, September 12, 2003, 4:41:04 AM, carl wrote:
> HTTP post example. Includes both sides (uploader and web server > script). Short and sweet: > http://www.rebol.net/cookbook/recipes/0026.html
Short and sweet indeed - but it has nothing to do with file uploading via "an HTML form." -- Best regards, Andreas

 [7/11] from: andreas:bolka:gmx at: 12-Sep-2003 17:39


Thursday, September 11, 2003, 6:27:15 AM, Tim wrote: [on parsing MIME multipart/form-data entities]
> It is called 'decode-multipart and if Andres isn't monitoring this > thread, I would be happy to provide it.
Thanks Tim :) Regarding Patrick's original request: I'd suggest you take a look at/do a search thru the list archives, as there have been various threads discussing "HTTP file uploading." (search for e.g. decode-multipart-form-data) A simple example of how to achieve what you want: ; decodes the POST data data: decode-multipart-form-data system/options/cgi/content-type read-post-data ; "thefile" is the name of your input field file: select data to-set-word "thefile" fname: last parse/all to-rebol-file data/filename "/\" write/binary fname file/content However, this does not contain any kind of validation. You need two functions (read-post-data and decode-multipart-form-data) for this to work, which are attached below - beware of eventual line wrappings. I am currently quite busy with getting my websites back up and running. Once this is done, I will eventually write a short tutorial on this sort of CGI stuff. I fear that decode-multipart-form-data is too large for typical cookbook recipes, but maybe it will become part of REBOL/Core one day. --- snip - read-post-data --- read-post-data: func [ {Reads the HTTP entity body} /safe "Disables evaluation of content-length header." /local len data tmp ] [ len: load any [ all [safe "65536"] system/options/cgi/content-length "0" ] data: make string! len tmp: make string! len while [ 0 < read-io system/ports/input tmp len ] [ insert tail data tmp clear tmp ] data ] --- snap --- --- snip - decode-multipart-form-data --- REBOL [ Title: "decode-multipart-form-data" Authors: [ "Andreas Bolka" ] Contributors: [ ] Date: 2003-02-22 History: [ 2002-06-18 abolka "initial release" 2003-02-21 abolka "major bugfixes and cleanup. example improved." 2003-02-22 abolka "another parsing bug fixed" 2003-09-12 abolka "fixed n/v-handling bug, noted by Marc Meurrens" ] Rights: { Copyright (C) 2002-2003 by Andreas Bolka Licensed under the Academic Free License version 1.1. See: <URL:http://earl.strain.at/license/afl> or <URL:http://www.rosenlaw.com/afl.html> } Version: 1.4 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" ] Parts of the form-data with content-type text/plain and no filename attribute in the content dispostition will be translated to basic name value pairs as in the example above. Parts having with a content-type different from text/plain and/or a filename attribute in their content disposition will be translated to object!'s with the following fields: filename, type, content. An example. Imagine an HTML form like the following: <form method="post" enctype="multipart/form-data"> <input type="text" name="field1" value="foo" /> <input type="file" name="field2" /> </form> Once this form is submitted with "foo" in field1 and a file called "bar.txt" containing the three bytes "nuf" in field2, this will result in the following to be returned from 'decode-multipart-form-data: [ field1: "foo" field2: make object! [ filename: "bar.txt" type: "text/plain" content: "nuf" ] ] } ] decode-multipart-form-data: func [ p-content-type p-post-data /local list ct bd delim-beg delim-end non-cr non-lf non-crlf mime-part ] [ list: copy [] if not found? find p-content-type "multipart/form-data" [ return list ] ct: copy p-content-type bd: join "--" copy find/tail ct "boundary=" delim-beg: join bd crlf delim-end: join crlf bd non-cr: complement charset reduce [ cr ] non-lf: complement charset reduce [ newline ] non-crlf: [ non-cr | cr non-lf ] mime-part: [ ( ct-dispo: content: none ct-type: "text/plain" ) delim-beg ; mime-part start delimiter "content-disposition: " copy ct-dispo any non-crlf crlf opt [ "content-type: " copy ct-type any non-crlf crlf ] crlf ; content delimiter copy content to delim-end crlf ; mime-part end delimiter ( handle-mime-part ct-dispo ct-type content ) ] handle-mime-part: func [ p-ct-dispo p-ct-type p-content /local tmp name value val-p ] [ p-ct-dispo: parse p-ct-dispo {;="} name: to-set-word (select p-ct-dispo "name") either (none? tmp: select p-ct-dispo "filename") and (found? find p-ct-type "text/plain") [ value: content ] [ value: make object! [ filename: copy tmp type: copy p-ct-type content: either none? p-content [ none ] [ copy p-content ] ] ] either val-p: find list name [ change/only next val-p compose [ (first next val-p) (value) ] ] [ append list compose [ (to-set-word name) (value) ] ] ] use [ ct-dispo ct-type content ] [ parse/all p-post-data [ some mime-part "--" crlf ] ] list ] --- snap --- -- Best regards, Andreas

 [8/11] from: andreas:bolka:gmx at: 12-Sep-2003 17:51


Friday, September 12, 2003, 5:26:04 PM, Andreas wrote:
> Friday, September 12, 2003, 4:41:04 AM, carl wrote: >> HTTP post example. Includes both sides (uploader and web server >> script). Short and sweet: >> http://www.rebol.net/cookbook/recipes/0026.html > Short and sweet indeed - but it has nothing to do with file > uploading via "an HTML form."
Sorry for this non-constructive post - please don't regard it as an offence. I posted another reply to Patrick's original question explaining how to achieve what he requested. -- Best regards, Andreas

 [9/11] from: pat:scotto:wanadoo at: 13-Sep-2003 9:36


thank you for your post , but andreas bolka understood what I neeed: I search THE cgi which get a file from a html , for exemple a form like that : <form method="post" enctype="multipart/form-data" action="upload.r"> <input type="hidden" name="path" value="my_path"> <input type="file" name="thefile" > <br><input type="submit" name="taskSubmit" value="writeThat">To Submit</form> your example is download.r and no an upload.r ;-) view from the navigator thank for your answer patrick .... [carl--rebol--com] a écrit:

 [10/11] from: g:santilli:tiscalinet:it at: 13-Sep-2003 10:56


Hi Andreas, On Friday, September 12, 2003, 5:39:47 PM, you wrote: AB> --- snip - read-post-data --- AB> read-post-data: func [ AB> {Reads the HTTP entity body} AB> /safe "Disables evaluation of content-length header." AB> /local len data tmp AB> ] [ AB> len: load any [ all [safe "65536"] system/options/cgi/content-length "0" ] AB> data: make string! len AB> tmp: make string! len AB> while [ 0 < read-io system/ports/input tmp len ] [ AB> insert tail data tmp AB> clear tmp AB> ] AB> data AB> ] AB> --- snap --- BTW, in Temple I'm just using something like: set-modes system/ports/input [binary: on] content: copy/part system/ports/input content-length (after checking the content length exists and attempting a to integer! etc.). I think that if you want to keep your /SAFE refinement it should be possible to just use: set-modes system/ports/input [binary: on] content: copy system/ports/input Of course very old versions of /Core may still require using READ-IO like in your code above. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [11/11] from: andreas:bolka:gmx at: 13-Sep-2003 16:41


Saturday, September 13, 2003, 10:56:19 AM, Gabriele wrote:
> BTW, in Temple I'm just using something like: > set-modes system/ports/input [binary: on] > content: copy/part system/ports/input content-length > (after checking the content length exists and attempting a to > integer! etc.).
My original code stems from a /Core 2.5.0 background and AFAIR the 'read-io loop was necessary on either linux or win32. Nevertheless your suggestion works fine (at least with core2.5.6 on win32) and I'll drop the old code once I've verified that it works fine on linux too. So thanks a lot :) -- Best regards, Andreas

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted