One more question about Rev cgi & binary data

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

One more question about Rev cgi & binary data

jbv-2
Hi guys,

Has anyone already tried to parse data from a multipart/form-data html
form
(that contains a type=file element) with Rev cgi ?
I've done it successfully in the past with ascii data, but now I'm
trying to post
jpeg data along with other parameters (height & with of the pic, session
#...)
in the same form, and obviously the jpeg binary data get corrupted in
the process...

Any idea ? Or will I have to use php again (sigh) ?

Best,
JB

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

masmit
JB, you may need to base64 encode the binary data.

Best,

Mark

On 25 Apr 2008, at 21:18, jbv wrote:

> Hi guys,
>
> Has anyone already tried to parse data from a multipart/form-data html
> form
> (that contains a type=file element) with Rev cgi ?
> I've done it successfully in the past with ascii data, but now I'm
> trying to post
> jpeg data along with other parameters (height & with of the pic,  
> session
> #...)
> in the same form, and obviously the jpeg binary data get corrupted in
> the process...
>
> Any idea ? Or will I have to use php again (sigh) ?
>
> Best,
> JB
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

jbv-2


Mark ,

> JB, you may need to base64 encode the binary data.

you mean in the html form, before uploading ?

JB


_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

masmit
I'd think you'd need to base64 encode the data before adding it to  
the form, but I must admit that I haven't actually done this.

Best,

Mark

On 25 Apr 2008, at 21:35, jbv wrote:

>
>
> Mark ,
>
>> JB, you may need to base64 encode the binary data.
>
> you mean in the html form, before uploading ?
>
> JB
>
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

Richard Miller-5
In reply to this post by jbv-2
JB,

Here's the solution which works for me. I know it seems a bit  
bizarre. It took many attempts to figure out how to get it to work  
reliably. But this works all the time.

Best,
Richard Miller

---------------------------
  -- buffer has the incoming data stream
   put buffer into temp
   put empty into pictfile
   put offset("image/jpeg",temp) into xx
   if xx <> 0 then
     put xx+14 into xx
     put char xx to (the length of temp) of temp into pictdata
     put char 1 to xx-1 of temp into tdata
     repeat with i = the length of pictdata down to 1
       if chartonum(char i of pictdata) is 0 then
         put i into holdit
         exit repeat
       end if
     end repeat
     delete char (holdit+1) to the length of pictdata of pictdata
     put "binfile:TempPict_" & the milliseconds & ".jpg" into PictFile
    -- these next steps are critical. It doesn't work otherwise.  
Field "temp2" is just an empty text field on the cgi stack
     put pictdata into url PictFile
     put url PictFile into pictdata
     put pictdata into fld "temp2"
     put fld "temp2" into url PictFile

The file PictFile will now be a regular jpeg file you can read and  
manipulate as you would any jpeg file



On Apr 25, 2008, at 4:18 PM, jbv wrote:

> Hi guys,
>
> Has anyone already tried to parse data from a multipart/form-data html
> form
> (that contains a type=file element) with Rev cgi ?
> I've done it successfully in the past with ascii data, but now I'm
> trying to post
> jpeg data along with other parameters (height & with of the pic,  
> session
> #...)
> in the same form, and obviously the jpeg binary data get corrupted in
> the process...
>
> Any idea ? Or will I have to use php again (sigh) ?
>
> Best,
> JB
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

jbv-2


Richard,

Thank for the script, but your method implies the use of a cgi
stack... what if a plain text script is used ?
Actually, I'm looking towards a php solution right now...

Best,
JB

> JB,
>
> Here's the solution which works for me. I know it seems a bit
> bizarre. It took many attempts to figure out how to get it to work
> reliably. But this works all the time.
>
> Best,
> Richard Miller
>
> ---------------------------
>   -- buffer has the incoming data stream
>    put buffer into temp
>    put empty into pictfile
>    put offset("image/jpeg",temp) into xx
>    if xx <> 0 then
>      put xx+14 into xx
>      put char xx to (the length of temp) of temp into pictdata
>      put char 1 to xx-1 of temp into tdata
>      repeat with i = the length of pictdata down to 1
>        if chartonum(char i of pictdata) is 0 then
>          put i into holdit
>          exit repeat
>        end if
>      end repeat
>      delete char (holdit+1) to the length of pictdata of pictdata
>      put "binfile:TempPict_" & the milliseconds & ".jpg" into PictFile
>     -- these next steps are critical. It doesn't work otherwise.
> Field "temp2" is just an empty text field on the cgi stack
>      put pictdata into url PictFile
>      put url PictFile into pictdata
>      put pictdata into fld "temp2"
>      put fld "temp2" into url PictFile
>
> The file PictFile will now be a regular jpeg file you can read and
> manipulate as you would any jpeg file

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

Richard Miller-5
JB,

I've found a stack script more flexible that a text script, and it  
takes only a few minutes to convert from text to stack.

Best,
Richard



On Apr 26, 2008, at 12:56 PM, jbv wrote:

>
>
> Richard,
>
> Thank for the script, but your method implies the use of a cgi
> stack... what if a plain text script is used ?
> Actually, I'm looking towards a php solution right now...
>
> Best,
> JB
>
>> JB,
>>
>> Here's the solution which works for me. I know it seems a bit
>> bizarre. It took many attempts to figure out how to get it to work
>> reliably. But this works all the time.
>>
>> Best,
>> Richard Miller
>>
>> ---------------------------
>>   -- buffer has the incoming data stream
>>    put buffer into temp
>>    put empty into pictfile
>>    put offset("image/jpeg",temp) into xx
>>    if xx <> 0 then
>>      put xx+14 into xx
>>      put char xx to (the length of temp) of temp into pictdata
>>      put char 1 to xx-1 of temp into tdata
>>      repeat with i = the length of pictdata down to 1
>>        if chartonum(char i of pictdata) is 0 then
>>          put i into holdit
>>          exit repeat
>>        end if
>>      end repeat
>>      delete char (holdit+1) to the length of pictdata of pictdata
>>      put "binfile:TempPict_" & the milliseconds & ".jpg" into  
>> PictFile
>>     -- these next steps are critical. It doesn't work otherwise.
>> Field "temp2" is just an empty text field on the cgi stack
>>      put pictdata into url PictFile
>>      put url PictFile into pictdata
>>      put pictdata into fld "temp2"
>>      put fld "temp2" into url PictFile
>>
>> The file PictFile will now be a regular jpeg file you can read and
>> manipulate as you would any jpeg file
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

jbv-2


Richard,

I see...

One more question about the incoming data stream : is the jpeg data raw
data (as uploaded by a type=file element in an html form for instance) or
is base64encoded ?

Thanks,
JB

> JB,
>
> I've found a stack script more flexible that a text script, and it
> takes only a few minutes to convert from text to stack.
>
> Best,
> Richard
>
> On Apr 26, 2008, at 12:56 PM, jbv wrote:
>
> >
> >
> > Richard,
> >
> > Thank for the script, but your method implies the use of a cgi
> > stack... what if a plain text script is used ?
> > Actually, I'm looking towards a php solution right now...
> >
> > Best,
> > JB
> >
> >> JB,
> >>
> >> Here's the solution which works for me. I know it seems a bit
> >> bizarre. It took many attempts to figure out how to get it to work
> >> reliably. But this works all the time.
> >>
> >> Best,
> >> Richard Miller
> >>
> >> ---------------------------
> >>   -- buffer has the incoming data stream
> >>    put buffer into temp
> >>    put empty into pictfile
> >>    put offset("image/jpeg",temp) into xx
> >>    if xx <> 0 then
> >>      put xx+14 into xx
> >>      put char xx to (the length of temp) of temp into pictdata
> >>      put char 1 to xx-1 of temp into tdata
> >>      repeat with i = the length of pictdata down to 1
> >>        if chartonum(char i of pictdata) is 0 then
> >>          put i into holdit
> >>          exit repeat
> >>        end if
> >>      end repeat
> >>      delete char (holdit+1) to the length of pictdata of pictdata
> >>      put "binfile:TempPict_" & the milliseconds & ".jpg" into
> >> PictFile
> >>     -- these next steps are critical. It doesn't work otherwise.
> >> Field "temp2" is just an empty text field on the cgi stack
> >>      put pictdata into url PictFile
> >>      put url PictFile into pictdata
> >>      put pictdata into fld "temp2"
> >>      put fld "temp2" into url PictFile
> >>
> >> The file PictFile will now be a regular jpeg file you can read and
> >> manipulate as you would any jpeg file
> >
> > _______________________________________________
> > use-revolution mailing list
> > [hidden email]
> > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-revolution
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

Dave Cragg-2
In reply to this post by jbv-2

On 25 Apr 2008, at 21:18, jbv wrote:

> Hi guys,
>
> Has anyone already tried to parse data from a multipart/form-data html
> form
> (that contains a type=file element) with Rev cgi ?
> I've done it successfully in the past with ascii data, but now I'm
> trying to post
> jpeg data along with other parameters (height & with of the pic,  
> session
> #...)
> in the same form, and obviously the jpeg binary data get corrupted in
> the process...

I've done this before with jpeg files uploaded as binary data. I can't  
find the script I used, but I think the handler below is what I used  
to parse the form data. It's based on a libCGI script that Jacqueline  
Gay used to distribute. It will handle standard and multipart forms.

If you need to find out how the data was encoded (e.g. whether base64  
or binary) then I think you'll need to look for a "Content-transfer-
encoding:" header somewhere below the boundary for the file part.

Cheers
Dave

##########################################

//assumes sPostdata already contains the entire posted data
// watch for wrapping in the email

local sCGIData, sPostdata

on parsePostData
        if sPostdata is empty then exit parsePostData
        if matchText($CONTENT_TYPE,"multipart/form-data;  
*boundary=(.*)",tMimeBoundary) then
      stripQuotes tMimeBoundary
     
      put lineOffset(tMimeBoundary,sPostdata) into tStartLine
      if tStartLine = 0 then exit parsePostdata
      repeat forever
      put lineOffset(tMimeBoundary,sPostdata, tStartLine + 1) +  
(tStartLine + 1) into tEndline
      if tEndline < 1 then exit repeat
                        if matchText(line tStartLine to tEndLine of sPostdata,"Content-
Disposition: +form-data; +name="&quote&"([^"&quote&"]+)",tName) then
                                put lineOffset(CRLF & CRLF, line tStartLine to tEndLine of  
sPostdata) + tStartLine + 1 into tDataOffset
                               
                                put line tDataOffset to tEndLine - 1 of sPostdata into tValue
                                rStripCR tValue
                                put tValue into sCGIData[tName]
                                put tEndLine into tStartLine
                        else
                                exit repeat
          end if
      end repeat
     else  ##assume www form urlencoded
      if sPostdata <> empty then split sPostdata  by "&" and "="
      repeat for each line tKey in the keys of sPostData
      put URLDecode(sPostData[tKey]) into sCGIData[tKey]
      end repeat
    end if
end parsePostData
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

J. Landman Gay
Dave Cragg wrote:
>
> On 25 Apr 2008, at 21:18, jbv wrote:

>> Has anyone already tried to parse data from a multipart/form-data html
>> form
>> (that contains a type=file element) with Rev cgi ?
>> I've done it successfully in the past with ascii data, but now I'm
>> trying to post
>> jpeg data along with other parameters (height & with of the pic, session
>> #...)
>> in the same form, and obviously the jpeg binary data get corrupted in
>> the process...
>
> I've done this before with jpeg files uploaded as binary data. I can't
> find the script I used, but I think the handler below is what I used to
> parse the form data. It's based on a libCGI script that Jacqueline Gay
> used to distribute. It will handle standard and multipart forms.

Just for the record, libCGI is Rodney Tamblyn and Monte Goulding's work.
The link I used to have for it is broken now though; if anyone has a
more recent one I can update my site.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

Richard Miller-5
In reply to this post by jbv-2
It's for conventional raw data as uploaded by type=file element.

Richard


On Apr 26, 2008, at 2:25 PM, jbv wrote:

>
>
> Richard,
>
> I see...
>
> One more question about the incoming data stream : is the jpeg data  
> raw
> data (as uploaded by a type=file element in an html form for  
> instance) or
> is base64encoded ?
>
> Thanks,
> JB
>
>> JB,
>>
>> I've found a stack script more flexible that a text script, and it
>> takes only a few minutes to convert from text to stack.
>>
>> Best,
>> Richard
>>
>> On Apr 26, 2008, at 12:56 PM, jbv wrote:
>>
>>>
>>>
>>> Richard,
>>>
>>> Thank for the script, but your method implies the use of a cgi
>>> stack... what if a plain text script is used ?
>>> Actually, I'm looking towards a php solution right now...
>>>
>>> Best,
>>> JB
>>>
>>>> JB,
>>>>
>>>> Here's the solution which works for me. I know it seems a bit
>>>> bizarre. It took many attempts to figure out how to get it to work
>>>> reliably. But this works all the time.
>>>>
>>>> Best,
>>>> Richard Miller
>>>>
>>>> ---------------------------
>>>>   -- buffer has the incoming data stream
>>>>    put buffer into temp
>>>>    put empty into pictfile
>>>>    put offset("image/jpeg",temp) into xx
>>>>    if xx <> 0 then
>>>>      put xx+14 into xx
>>>>      put char xx to (the length of temp) of temp into pictdata
>>>>      put char 1 to xx-1 of temp into tdata
>>>>      repeat with i = the length of pictdata down to 1
>>>>        if chartonum(char i of pictdata) is 0 then
>>>>          put i into holdit
>>>>          exit repeat
>>>>        end if
>>>>      end repeat
>>>>      delete char (holdit+1) to the length of pictdata of pictdata
>>>>      put "binfile:TempPict_" & the milliseconds & ".jpg" into
>>>> PictFile
>>>>     -- these next steps are critical. It doesn't work otherwise.
>>>> Field "temp2" is just an empty text field on the cgi stack
>>>>      put pictdata into url PictFile
>>>>      put url PictFile into pictdata
>>>>      put pictdata into fld "temp2"
>>>>      put fld "temp2" into url PictFile
>>>>
>>>> The file PictFile will now be a regular jpeg file you can read and
>>>> manipulate as you would any jpeg file
>>>
>>> _______________________________________________
>>> use-revolution mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>> _______________________________________________
>> use-revolution mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

jbv-2
In reply to this post by Dave Cragg-2


Dave,

Thanks for the code; I'll try that as well, although the problem is not
to parse data from multipart encoded forms, but to keep binary data
consistent inside Rev variables...
I'm probably doing something wrong, but as soon as I use "line" or
"lineoffset" in a script, or even try to count the number of chars,
binary data seem to get corrupted... Probably because the "return" char
is part of the binary data...

JB


>
>
> I've done this before with jpeg files uploaded as binary data. I can't
> find the script I used, but I think the handler below is what I used
> to parse the form data. It's based on a libCGI script that Jacqueline
> Gay used to distribute. It will handle standard and multipart forms.
>
> If you need to find out how the data was encoded (e.g. whether base64
> or binary) then I think you'll need to look for a "Content-transfer-
> encoding:" header somewhere below the boundary for the file part.
>
> Cheers
> Dave
>
> ##########################################
>
> //assumes sPostdata already contains the entire posted data
> // watch for wrapping in the email
>
> local sCGIData, sPostdata
>
> on parsePostData
>         if sPostdata is empty then exit parsePostData
>         if matchText($CONTENT_TYPE,"multipart/form-data;
> *boundary=(.*)",tMimeBoundary) then
>         stripQuotes tMimeBoundary
>
>         put lineOffset(tMimeBoundary,sPostdata) into tStartLine
>         if tStartLine = 0 then exit parsePostdata
>         repeat forever
>                 put lineOffset(tMimeBoundary,sPostdata, tStartLine + 1) +
> (tStartLine + 1) into tEndline
>                 if tEndline < 1 then exit repeat
>                         if matchText(line tStartLine to tEndLine of sPostdata,"Content-
> Disposition: +form-data; +name="&quote&"([^"&quote&"]+)",tName) then
>                                 put lineOffset(CRLF & CRLF, line tStartLine to tEndLine of
> sPostdata) + tStartLine + 1 into tDataOffset
>
>                                 put line tDataOffset to tEndLine - 1 of sPostdata into tValue
>                                 rStripCR tValue
>                                 put tValue into sCGIData[tName]
>                                 put tEndLine into tStartLine
>                         else
>                                 exit repeat
>                 end if
>         end repeat
>      else  ##assume www form urlencoded
>         if sPostdata <> empty then split sPostdata  by "&" and "="
>         repeat for each line tKey in the keys of sPostData
>                 put URLDecode(sPostData[tKey]) into sCGIData[tKey]
>         end repeat
>         end if
> end parsePostData
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: One more question about Rev cgi & binary data

Andre Garzia-3
Friends,

I do have a libCGI that I think is the most recent one somewhere on my
drive, I think it is version 1.0.1 or something like it.

I´ve took this handler and adapted it to work with Rockets CGI
libraries in case anyone is interested.

Anyone else interested?

Andre


--
http://www.andregarzia.com All We Do Is Code.
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution