Thank you, Scott, for digging this up! I can now upload large files using
multipart/form-data. See for yourself by uploading a nice big
browser-capable image here...
http://www.fargonews.com/post-data.html
The updated function follows...
decode-multipart: make object! [
form-data: func [
][
post-data: make string! 100000
while [0 < read-io system/ports/input post-data 100000] []
post-data: make binary! post-data
parse/all post-data [to "----" copy text thru "^/" (boundary: copy
text)]
cd-block: []
parse/all post-data [
any [thru boundary copy text [to boundary | to end] (text: make
binary! text append cd-block text)]]
cd-input: []
foreach cd cd-block [
either find cd "filename" [
parse/all cd [thru {name="} copy text to {"} (append
cd-input text)]
parse/all cd [thru {filename="} copy text to {"}
(file-path-string: copy text)]
file-path-block: parse/all file-path-string {\/"}
filename: last file-path-block
parse/all cd [thru {Content-Type: } copy text to {^M^/}
(file-mime-type: copy text)]
; parse/all cd [thru {^M^/^M^/} copy text to {^M^/} (text:
make binary! text append cd-input text)]
parse/all cd [thru {^M^/^M^/} copy text [to boundary | to
end] (text: make binary! text append cd-input text)]
][
parse/all cd [thru {name="} copy text to {"} (append cd-input
text)]
parse/all cd [thru {^M^/^M^/} copy text to {^M^/} (append
cd-input text)]
]
]
cd-input: head cd-input
object-data: make object! []
for x 1 (length? cd-input) 2 [
variable: first cd-input
cd-input: next cd-input
value: first cd-input
either binary? value [
make-object-data: reform [rejoin [{object-data: make
object-data [} (variable) {: } (value) {]}]]
][
make-object-data: reform [rejoin [{object-data: make
object-data [} (variable) {: ^{} (value) {^}]}]]
]
do make-object-data
cd-input: next cd-input
]
make-object-data: reform [rejoin [{object-data: make object-data
[filename: ^{} (filename) {^}]}]]
do make-object-data
make-object-data: reform [rejoin [{object-data: make object-data
[file-mime-type: ^{} (file-mime-type) {^}]}]]
do make-object-data
object-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
[EMAIL PROTECTED]
"GS Jones"
<gjones05@mail. To: <[EMAIL PROTECTED]>
orion.org> cc:
Sent by: Subject: [REBOL] Re: retrieve-user-data
needs help
rebol-bounce@re
bol.com
05/04/2001
07:16 AM
Please respond
to rebol-list
From: <[EMAIL PROTECTED]>
> I'm trying to incorporate my 'decode-multipart/form-data function into
the
> commonly used 'retrieve-user-data function, but I am getting something
> wrong. The function works now for GET operations but not for POST.
>
> If I use 'read-io on system/ports/input, that clears the port, correct?
<snip>
Hi, Ryan,
On May 2nd on a different thread ("read bug?"), Holger said (excerpt):
<excerpt>
About the other problem, i.e. getting data from a POST request
within a REBOL CGI script: keep in mind that read-io is a
very-low-level read request that returns as soon as the OS
returns something. The amount of data returned is not necessarily
what was requested. It can be less. This is not a bug, it is by
design. If you see a limit of around 4096 bytes then this is caused
by how the OS clusters its data. What you need to do in a CGI
script is loop until read-io returns 0, e.g.
cgi-str: make string! 100000
while [0 < read-io system/ports/input cgi-str 100000] []
</excerpt>
I've not had a chance to play with this approach. Maybe it will help.
--Scott Jones
> Then...
>
> return make object! decode-cgi input
>
> ...will no longer work. But if I replace that line with...
>
> return make object! decode-cgi post-data
>
> ...thus using the data I have already retrieved, (using 'post-data in my
> function below instead of 'input) the function does not work.
>
> Why?
>
> 'decode-cgi requres an argument of 'any-string! and should be able to
> handle my 'post-data argument, shouldn't it?
>
> Here is the version of 'retrieve-user-data I am trying to use...
>
> retrieve-user-data: func [][
> either system/options/cgi/request-method = "POST" [
> content-length: 20 + load system/options/cgi/content-length
> post-data: make string! content-length
> read-io system/ports/input post-data content-length
> parse/all post-data [thru "Content-Disposition: " copy text to
";"
> (post-type: copy text)]
> switch/default post-type [
> "form-data" [
> decode-multipart/form-data
> ]
> return make object! decode-cgi input
> ]
> ][
> return make object! decode-cgi system/options/cgi/query-string
> ]
> ]
>
> 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
> [EMAIL PROTECTED]
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.
>
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.