Content-Length. CRLF is not there to tell you when a request is
complete, but instead how to divide parts of a request. A request is
not actually complete until you have received every byte. Once you
do, you should remove that number of bytes from your buffer and
continue processing as it's possible to receive 1 1/2 requests and
other weird things.
You may want to look at my RB HTTP server as I've done this (not
directly uploading, but handling POST requests) already. The classes
give you quick and easy access to the headers and content without
knowing how HTTP really works.
<http://www.thezaz.org/Downloads/REALbasic/Server/HTTP/>
--
Thom McGrath
The ZAZ Studios
<http://www.thezaz.com/> AIM: thezazstudios
On Oct 8, 2006, at 1:56 AM, Jeff Ayling wrote:
Hi all,
I am aware of many RB examples regarding uploading a file to a php
script on a web server however I am wondering if anyone has any
tips or examples regarding uploading a file from a web page to a
RealBasic built web server.
If simply receiving a GET then the following works well to detect
when the request has been received:
if InStrB( LookAhead(), chr(13) + chr(10) ) = 0 then return
However when receiving a POST containing a file being uploaded
there may be more than one chr(13)+chr(10) - I am wondering if
someone could suggest a better way to detect when the entire
request and file have been received.
Here is an example file upload request - including headers and file:
POST /upload.dt HTTP/1.1
Accept: */*
Accept-Language: en
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)
AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3
Content-Length: 1389
Content-Type: multipart/form-data; boundary=----------0xKhTmLbOuNdArY
Connection: keep-alive
Host: localhost:7777
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name="datafile";
filename="bigsmile3.gif"
Content-Type: image/gif
file content is inserted here
------------0xKhTmLbOuNdArY--
...and here is the form I am using to upload the file:
<form action="http://localhost:7777/upload.dt"
enctype="multipart/form-data" method="post">
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="datafile" size="40">
</p>
<p>
<input type="submit" value="Send">
</p>
</form>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>