On-Rev File Browser Upload Dialog

Richard Gaskin ambassador at fourthworld.com
Thu Oct 21 20:29:45 EDT 2010


Matthias Rebbe wrote:
> i see in your example that you are submitting the form to mydropbox.cgi. Is this cgi made in rev?
> and if so, would you share it?

That particular CGI is written in Perl, but copied below is an early 
draft of one I've been working on for RevCloud.

Note that it's very much an early draft and hasn't had much testing, and 
that it's designed only to parse the multi-part form data into a 
memory-based array for other functions to write out to disk if needed, 
so while it's held up okay when sending files of a few MBs it doesn't 
provide asynchronous feedback and isn't suitable for really large files 
like videos.  I would be grateful if someone had a more robust 
asynchronous solution they could share.



on _cgiGetInput
   if $REQUEST_METHOD is "POST" then
     -- POST: -----------------------------------------
     put empty into tBuffer
     repeat until length(tBuffer) >= $CONTENT_LENGTH
       read from stdin until empty
       put it after tBuffer
     end repeat
     if tBuffer is empty then put $QUERY_STRING into tBuffer
     --
     if char 1 to 30 of $CONTENT_TYPE = "multipart/form-data; boundary=" 
then
       -- MULTI-PART FORM:
       put $CONTENT_TYPE into tMimeBoundary
       delete char 1 to 30 of tMimeBoundary
       if char 1 of tMimeBoundary = quote then delete char 1 of 
tMimeBoundary
       if last char of tMimeBoundary = quote then delete last char of 
tMimeBoundary
       --
       repeat
         -- Get next part:
         put lineoffset(tMimeBoundary, tBuffer) into  tStart
         if tStart = 0 then exit repeat
         delete line 1 to tStart of tBuffer
         put lineoffset(tMimeBoundary, tBuffer) into tEnd
         if tEnd = 0 then exit repeat
         put line 1 to (tEnd-1) of tBuffer into tPartData
         delete last char of tPartData -- trailing CR
         --
         -- Parse part:
         put line 1 of tPartData into tInfo
         set the itemdel to ";"
         put item 2 of tInfo into tName
         delete char 1 to 7 of tName
         delete last char of tName
         if last char of tName  = quote then delete last char of tName
         --
         put empty into tFileName
         if (the number of items of tInfo = 3) \
             AND (char 1 to 10 of item 3 of tInfo = " filename=") then
           -- file data:
           put item 3 of tInfo into tFileName
           delete char 1 to 11 of tFileName
           delete last char of tFileName
           if last char of tFileName  = quote then delete last char of 
tFileName
           --
           # put tFileName into gCGIFileNamesA[tName]

         end if
         -- get raw data:
         if char 1 to 13 of line 2 of tPartData = "Content-Type:" then
           delete line 1 to 3 of tPartData
         else
           delete line 1 to 2 of tPartData
         end if
         if tFileName is empty then
           put tPartData into gCGIDataInA[tName]
         else
           put tPartData into gCGIDataInA["file:"&tFileName]
         end if
       end repeat
       --
     else
       -- NORMAL FORM:
       put tBuffer into gCGIDataInA
       split gCGIDataInA  by "&" and "="
       repeat for each line tKey in the keys of gCGIDataInA
         put URLDecode(gCGIDataInA[tKey]) into gCGIDataInA[tKey]
       end repeat
     end if
     --
   else
     -- GET: -----------------------------------------
     put $QUERY_STRING into gCGIDataInA
     split gCGIDataInA by "&" and "="
     repeat for each line tKey in the keys of gCGIDataInA
       put urlDecode(gCGIDataInA[tKey]) into gCGIDataInA[tKey]
     end repeat
   end if
end _cgiGetInput


--
  Richard Gaskin
  Fourth World
  LiveCode training and consulting: http://www.fourthworld.com
  Webzine for LiveCode developers: http://www.LiveCodeJournal.com
  LiveCode Journal blog: http://LiveCodejournal.com/blog.irv




More information about the use-livecode mailing list