enctype="multipart/form-data"
[1/5] from: ryan:christiansen:intellisol at: 25-Apr-2001 15:46
I want to be able to submit image files using POST and to save those image
files from the POSTed input. I am taking steps in this direction, and so I
gave my form tags a new enctype attribute.
I'm using the following function to make an object! out of POSTed data:
retrieve-user-data: func [] [
return make object! decode-cgi
either system/options/cgi/request-method = "POST" [
input
][
system/options/cgi/query-string
]
]
When I give the <FORM> tag enctype attribute the "multipart/form-data"
value, I get an error saying REBOL can't find the path to one of the
submitted values.
** Script Error: Invalid path value: actionType ** Where:
message-action-cgi ** Near: switch/default cgi-input/actionType
The form DOES submit input named actionType but apparently my REBOL code is
not decoding the input correctly. I am probably misunderstanding the
multipart/form-data concept. Does anyone here have an example of REBOL code
they use to decode POSTed multipart/form-data, especially data which
includes an image file posted using the <INPUT TYPE=FILE> tag?
Thanks.
Ryan C. Christiansen
Web Developer
Intellisol International
4733 Amber Valley Parkway
Fargo, ND 58104
701-235-3390 ext. 6671
FAX: 701-235-9940
http://www.intellisol.com
Global Leader in People Performance Software
_____________________________________
Confidentiality Notice
This message may contain privileged and confidential information. If you
think, for any reason, that this message may have been addressed to you in
error, you must not disseminate, copy or take any action in reliance on it,
and we would ask you to notify us immediately by return email to
[ryan--christiansen--intellisol--com]
[2/5] from: sterling:rebol at: 25-Apr-2001 13:23
REBOL does not parse multipart/form-data at this time. DECODE-CGI
only parses GET style requests which allows it to work for GET and
non-multipart POST data. Multipart ancoding is more complicated and
very much like an email message. If you want to implement your own
parser for this, I'd start with looking at import-email and related
functions.
If you get something running smoothly, we might be able to adapt it to
the current decode-cgi and have that do both.
Sterling
[3/5] from: ryan:christiansen:intellisol at: 25-Apr-2001 16:44
Is there an RFC or some other documentation for multipart/form-data?
Ryan C. Christiansen
Web Developer
Intellisol International
4733 Amber Valley Parkway
Fargo, ND 58104
701-235-3390 ext. 6671
FAX: 701-235-9940
http://www.intellisol.com
Global Leader in People Performance Software
_____________________________________
Confidentiality Notice
This message may contain privileged and confidential information. If you
think, for any reason, that this message may have been addressed to you in
error, you must not disseminate, copy or take any action in reliance on it,
and we would ask you to notify us immediately by return email to
[ryan--christiansen--intellisol--com]
[sterling--rebo]
l.com To: [rebol-list--rebol--com]
Sent by: cc:
rebol-bounce@ Subject: [REBOL] Re: enctype="multipart/form-data"
rebol.com
04/25/2001
03:23 PM
Please
respond to
rebol-list
REBOL does not parse multipart/form-data at this time. DECODE-CGI
only parses GET style requests which allows it to work for GET and
non-multipart POST data. Multipart ancoding is more complicated and
very much like an email message. If you want to implement your own
parser for this, I'd start with looking at import-email and related
functions.
If you get something running smoothly, we might be able to adapt it to
the current decode-cgi and have that do both.
Sterling
[4/5] from: jhagman:infa:abo:fi at: 26-Apr-2001 3:32
Quoting [ryan--christiansen--intellisol--com] ([ryan--christiansen--intellisol--com]):
> Is there an RFC or some other documentation for multipart/form-data?
You could see
RFC 1867 Form-based File Upload in HTML
It then contains references to other RFC in question.
--
Jussi Hagman CS in Åbo Akademi University
Studentbyn 4 D 33 [juhagman--abo--fi]
20540 Åbo [jhagman--infa--abo--fi]
Finland
[5/5] from: ljurado:bariloche:ar at: 29-Apr-2001 16:11
> I want to be able to submit image files using POST and to save those image
> files from the POSTed input. I am taking steps in this direction, and so I
> gave my form tags a new enctype attribute.
With this modified post.r script and form-upload.r I can upload binary
files (jpg, etc)
But this is today work , beware ....
Luis Rodriguez Jurado.
==================
#!c:/rebol.exe -cs
REBOL [
TITLE: "form-upload"
FILE: %form-upload.r
DATE: 29-April-2000
]
print "Content-Type: text/html^/^/"
print {
<form METHOD=POST ACTION="post.r"
enctype="multipart/form-data">
Enter a description of the file:: <input TYPE=text
SIZE=50 NAME=text><br>
Select the file: <input TYPE=file SIZE=15
NAME=myUpload><br><br><br>
<input TYPE=submit VALUE="post.r">
</FORM></INPUT>
}
#!c:/rebol.exe -cs
REBOL [
Title: "multipart POST"
Date: 15-Sep-1999
Version: 1.2
File: %POST.r
Author: "Andrew Grossman (modified by: Luis Rodriguez J -
.29-April-2000)"
Email: [grossdog--dartmouth--edu]
Owner: "REBOL Technologies"
Purpose: {
To decode multipart encoded POST requests, including file uploads.
}
Usage: {
Call this file in your CGI scriptand do decode-multi with a
file argument of the directory where uploaded files will go and
a logic argument to set whether files will be given the field they
were
uploaded as as a name. Files are saved and variables are decoded
and
set.
}
Notes: {
Fixed problem recognizing EOF.
Functionality is now rock solid. Function
calls won't change, so this is certainly useable.
See the comment in the decode-multi function if you need mime types.
Tested with MSIE and Netscape for Mac.
}
category: ['web 'cgi 'utility]
]
decode-multi: func [
file-dir [file!] {Directory in which to put uploaded files}
save-as-field [logic!] {save files as field name or uploaded
filename}
/local str boundary done name file done2 content
][
if equal? system/options/cgi/request-method "POST" [
either not parse system/options/cgi/content-type
["multipart/form-data" skip thru {boundary=} skip some {-}
copy boundary to end]
str: make string! input do decode-cgi str][
str: make string! input
done: false
while [not done] [
name: make string! ""
str: make string! input
either equal? "" str [done: true] [
either parse/all str [skip thru {name="} copy name to {"}
skip thru {filename="} copy file to {"} skip to end] [
str: make string! input
if not equal? str "" [str: make string! input]
comment {if you need mime put "parse/all str
["Content-Type:"
skip copy mime to end]" into the preceding if
block.}
done2: false
content: make string! ""
while [not done2] [
content-length: to-integer system/options/cgi/content-length
str: make string! content-length
read-io system/ports/input str content-length
either d: find/reverse tail str boundary [
e: find/reverse tail copy/part str (index? d)
{^/}
content: copy/part str (index? e) - 2
done2: true]
[
append content str
]
]
if not none? file
either save-as-field [name: dehex name write/binary
file-dir/:name content] [
file: dehex file write/binary file-dir/:file
content
]
]
][
parse str [skip thru {name="} copy name to {"}]
str: make string! input str: dehex make string! input
set to-word name str str: make string! input
]
]
]
]
]
]
decode-multi %. true
Librarian comment
Andreas Bolka's decode-multipart-form-data seems to be most often used as a base for handling multi-part forms.