Hardware Reference
In-Depth Information
Anatomy of a Multipart POST Request
HTML forms that use HTTP to enable file uploading are done with the POST request, as well as a special content type,
multipart/form-data , so the server knows how to interpret what comes through. Each element from the form is sent in a
separate part by a unique string. Here's what the server might see from the uploader script you wrote earlier:
8 Boundary: has to be a unique
string, but you can use whatever
you wish. Comes before each part.
POST /catcam/save2web.php HTTP/1.1
Host: www.example.com
Content-Type: multipart/form-data; boundary=----H4rkNrF
Content-Length: 40679
8 Value for this part.
------H4rkNrF
Content-Disposition: form-data; name="submit"
Upload
------H4rkNrF
Content-Disposition: form-data; name="file"; filename="catcam.jpg"
Content-Type: image/jpeg
8 Content-Disposition: says what
this part is. For files, also includes
the local path to the file.
8 Final boundary ends with an
extra two dashes.
[actual bytes of the file go here]
------H4rkNrF--
Putting It All Together
Finally, it's time to combine the Processing sketch, which
reads the serial port and calls the mailer script, with the
one that takes the image and calls the image uploader
script. The final sketch will work as shown in Figure 3-14.
All the action is driven by the serial input of sensor data. If
the received value is over the threshold, there's a cat there,
so the sketch takes a picture. If it's been an appropriate
time since the last picture, the picture is uploaded. If the
sensor value has just changed from below the threshold to
above, and enough time has passed since the last mail, the
sketch sends you mail that the cat just jumped on the mat.
Figure 3-14
The flowchart of the Cat Cam sketch.
Search WWH ::




Custom Search