need advice on parsing image data
[1/10] from: ryan::christiansen::intellisol::com at: 27-Apr-2001 15:28
When I post a form entry and a file using multipart/form-data encoding, I
get the following....
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="content"
content
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="file"; filename="D:
\fgonews\ad_graphic_01.jpg"
Content-Type: image/pjpeg
ÿØÿà (plus a whole bunch more characters that I am unable to
copy-and-paste)
-----------------------------7d1a92c9014c--
This is an easy parse. However, REBOL will not parse the image data. It
gets stuck when it reaches an unknown character, which shows up in Notepad
as a square. As you can see, I'm not even able to copy-and-paste the actual
image data from the text file into this e-mail. Does anyone have any advice
on how to parse this image 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]
[2/10] from: brett:codeconscious at: 28-Apr-2001 15:02
Hi Ryan,
I got the post-data file from the url of your earlier message.
I'm no expert but here's my thinking.
1) The data returned from the post should initially be treated as binary -
because you have image data that is binary and has not been encoded. So what
I did was use read/binary to get your post-data file. I don't know for sure,
but it is possible some clients may upload the file data in a different
encoding like Base 64 rather than straight binary. So you may need to handle
the case where a content-transfer-encoding header is given.
2) Though you data is binary doesn't mean you can't parse it like a string.
Just remember to use /all refinement of parse.
I already had some mime type handling stuff for emails. So I changed around
a little bit to handle your file as well. It is very possible I still
haven't handled the RFCs properly but it seems to work at the moment.
Using Rebo/View Try this script - The view part is just to show that I
succesfully got your image data.
do http://www.codeconscious.com/rebol-library/message-tools.r
post-data: read/binary http://www.fargonews.com/post-data
r: decode-mime-parts mime-parts? post-data
---------------------------7d1a92c9014c
write/binary %tf.jpg r/7/content
view layout [image %tf.jpg]
BTW I'd like to know how to display the image without having to write the
file first - anyone - please?
Hope it helps you.
Brett Handley
----- Original Message -----
From: <[ryan--christiansen--intellisol--com]>
To: <[rebol-list--rebol--com]>
Sent: Saturday, April 28, 2001 6:28 AM
Subject: [REBOL] need advice on parsing image data
When I post a form entry and a file using multipart/form-data encoding, I
get the following....
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="content"
content
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="file"; filename="D:
\fgonews\ad_graphic_01.jpg"
Content-Type: image/pjpeg
ÿØÿà (plus a whole bunch more characters that I am unable to
copy-and-paste)
-----------------------------7d1a92c9014c--
This is an easy parse. However, REBOL will not parse the image data. It
gets stuck when it reaches an unknown character, which shows up in Notepad
as a square. As you can see, I'm not even able to copy-and-paste the actual
image data from the text file into this e-mail. Does anyone have any advice
on how to parse this image 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]
[3/10] from: brett:codeconscious at: 28-Apr-2001 21:11
Me again.
I realised a few holes in my script. And your problem has given my some
angst with my message-tools.r script.
When dealing with emails we can use import-email which assumes that the
email has been read with a READ. The read does the line termination
conversion. So ok. But your post data file has shown that to deal with
binary data I would have to deal with CRLF line termination ( RFC1521
appendix G talks about this). So now I'm somewhat confused as to what I
should do to get my message-tools.r script handle mime-emails and
mime-forms.
Argh!
Brett.
----- Original Message -----
From: "Brett Handley" <[brett--codeconscious--com]>
To: <[rebol-list--rebol--com]>
Sent: Saturday, April 28, 2001 3:02 PM
Subject: [REBOL] Re: need advice on parsing image data
Hi Ryan,
I got the post-data file from the url of your earlier message.
I'm no expert but here's my thinking.
1) The data returned from the post should initially be treated as binary -
because you have image data that is binary and has not been encoded. So what
I did was use read/binary to get your post-data file. I don't know for sure,
but it is possible some clients may upload the file data in a different
encoding like Base 64 rather than straight binary. So you may need to handle
the case where a content-transfer-encoding header is given.
2) Though you data is binary doesn't mean you can't parse it like a string.
Just remember to use /all refinement of parse.
I already had some mime type handling stuff for emails. So I changed around
a little bit to handle your file as well. It is very possible I still
haven't handled the RFCs properly but it seems to work at the moment.
Using Rebo/View Try this script - The view part is just to show that I
succesfully got your image data.
do http://www.codeconscious.com/rebol-library/message-tools.r
post-data: read/binary http://www.fargonews.com/post-data
r: decode-mime-parts mime-parts? post-data
---------------------------7d1a92c9014c
write/binary %tf.jpg r/7/content
view layout [image %tf.jpg]
BTW I'd like to know how to display the image without having to write the
file first - anyone - please?
Hope it helps you.
Brett Handley
----- Original Message -----
From: <[ryan--christiansen--intellisol--com]>
To: <[rebol-list--rebol--com]>
Sent: Saturday, April 28, 2001 6:28 AM
Subject: [REBOL] need advice on parsing image data
When I post a form entry and a file using multipart/form-data encoding, I
get the following....
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="content"
content
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="file"; filename="D:
\fgonews\ad_graphic_01.jpg"
Content-Type: image/pjpeg
ÿØÿà (plus a whole bunch more characters that I am unable to
copy-and-paste)
-----------------------------7d1a92c9014c--
This is an easy parse. However, REBOL will not parse the image data. It
gets stuck when it reaches an unknown character, which shows up in Notepad
as a square. As you can see, I'm not even able to copy-and-paste the actual
image data from the text file into this e-mail. Does anyone have any advice
on how to parse this image 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]
[4/10] from: norsepower:uswest at: 28-Apr-2001 10:43
We do have a CRLF 'word in REBOL, correct? That could help with parse.
Are you saying that with multipart/form-data, Apache is generating POST data
which uses CRLF- instead of newline-terminated data?
-Ryan
[5/10] from: larry:ecotope at: 28-Apr-2001 15:01
Hi Brett,
>write/binary %tf.jpg r/7/content
>view layout [image %tf.jpg]
>BTW I'd like to know how to display the image without having to write the
file first - anyone - please?
Using your example, you can say
im: load r/7/content
view layout [image im]
or even
view layout [image load r/7/content]
Cheers
-Larry
[6/10] from: brett:codeconscious at: 29-Apr-2001 10:55
Yes and Yes.
As far as I can see, the official network form of the data uses CRLF (this
BTW is true of POP etc).
After using Rebol for a while, we may forget that a READ converts CRLF to a
newline - which is not so good for binary data - hence the /binary
refinement of READ. This fact escaped my memory until I read the section in
the Core manul on line conversion/endings. Hence, my issue in trying to
create a set of functions useful for post data and for email which we tend
to acquire with a READ in Rebol (for email is shouldn't be a problem because
Email generally does not handle binary data - attachments and encoded in a
mail-safe form before transport).
Brett.
[7/10] from: brett:codeconscious at: 29-Apr-2001 10:45
Ah too easy. Thanks.
Brett.
[8/10] from: deryk:iitowns at: 29-Apr-2001 11:41
Brett Handley wrote:
> Ah too easy. Thanks.
> Brett.
<<quoted lines omitted: 19>>
> >
> > view layout [image load r/7/content]
Might be too easy, but why is load even needed at all? if in this
example, r/7/content is set, known, and in memory.
Simply specifying:
view layout [image r/7/content]
Should be sufficient. I still have yet to wrap my head around rebol. I
know it is portrayed as an 'easy to learn, thought like' language but
some things like this still stump me. To me, the above layout line
would be the way I would think about writing it in human fashion.
Deryk
-- Binary/unsupported file stripped by Listar --
-- Type: application/x-pkcs7-signature
-- File: smime.p7s
-- Desc: S/MIME Cryptographic Signature
[9/10] from: brett:codeconscious at: 29-Apr-2001 16:16
I hope you will excuse another of my replies to myself.
I have spent quite a deal of time on the issue I mentioned earlier about
line termination and I have restructured fairly deeply
my script. So much so that I have deleted the %message-tools.r script from
my site and replaced it
with %mime-model.r which I think is a lot more sturdy as a solution.
It still needs work but should be more more useful now.
More comments in the code.
Any comments or bugs or improvements appreciated.
Brett.
[10/10] from: ryan:christiansen:intellisol at: 30-Apr-2001 14:32
> The data returned from the post should initially be treated
> as binary - because you have image data that is binary
> and has not been encoded. So what I did was use read/binary
> to get your post-data file.
I'm using 'read-io to retrieve the POSTed data. There is no /binary
refinement for 'read-io. Since 'read-io is a "low-level read from a port"
according to 'help, isn't it already retrieving the POSTed data in binary
form?
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]
"Brett Handley"
<[brett--codecons] To: <[rebol-list--rebol--com]>
cious.com> cc:
Sent by: Subject: [REBOL] Re: need advice on parsing image data
[rebol-bounce--re]
bol.com
04/28/2001
12:02 AM
Please respond
to rebol-list
Hi Ryan,
I got the post-data file from the url of your earlier message.
I'm no expert but here's my thinking.
1) The data returned from the post should initially be treated as binary -
because you have image data that is binary and has not been encoded. So
what
I did was use read/binary to get your post-data file. I don't know for
sure,
but it is possible some clients may upload the file data in a different
encoding like Base 64 rather than straight binary. So you may need to
handle
the case where a content-transfer-encoding header is given.
2) Though you data is binary doesn't mean you can't parse it like a string.
Just remember to use /all refinement of parse.
I already had some mime type handling stuff for emails. So I changed around
a little bit to handle your file as well. It is very possible I still
haven't handled the RFCs properly but it seems to work at the moment.
Using Rebo/View Try this script - The view part is just to show that I
succesfully got your image data.
do http://www.codeconscious.com/rebol-library/message-tools.r
post-data: read/binary http://www.fargonews.com/post-data
r: decode-mime-parts mime-parts? post-data
---------------------------7d1a92c9014c
write/binary %tf.jpg r/7/content
view layout [image %tf.jpg]
BTW I'd like to know how to display the image without having to write the
file first - anyone - please?
Hope it helps you.
Brett Handley
----- Original Message -----
From: <[ryan--christiansen--intellisol--com]>
To: <[rebol-list--rebol--com]>
Sent: Saturday, April 28, 2001 6:28 AM
Subject: [REBOL] need advice on parsing image data
When I post a form entry and a file using multipart/form-data encoding, I
get the following....
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="content"
content
-----------------------------7d1a92c9014c
Content-Disposition: form-data; name="file"; filename="D:
\fgonews\ad_graphic_01.jpg"
Content-Type: image/pjpeg
ÿØÿà (plus a whole bunch more characters that I am unable to
copy-and-paste)
-----------------------------7d1a92c9014c--
This is an easy parse. However, REBOL will not parse the image data. It
gets stuck when it reaches an unknown character, which shows up in Notepad
as a square. As you can see, I'm not even able to copy-and-paste the actual
image data from the text file into this e-mail. Does anyone have any advice
on how to parse this image 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]
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted