
Dear Larry,
I am trying to add an image to my web page and I am uncertain what I should do. How do I make the Rabbit web server send an image to my browser?
Roger D.
Hello Roger,
The best place to start this discussion is with the STATIC.C sample program located in the C:\DCRABBIT_XX.XX\Samples\TCPIP\HTTP directory. This Rabbit example program uses an image file called rabbit1.gif.
First on line 68 you can see we are importing an image into extended memory like this:
#ximport "samples/tcpip/http/pages/rabbit1.gif" rabbit1_gif
Then we setup .GIF files as a valid type of file for the web server in the MIME table on line 86:
SSPEC_MIMETABLE_START
SSPEC_MIME(".html", "text/html"),
SSPEC_MIME(".gif", "image/gif")
SSPEC_MIMETABLE_END
Next we associate our rabbit.gif file with the web server on line 100:
SSPEC_RESOURCETABLE_START
SSPEC_RESOURCE_XMEMFILE("/index.html", index_html),
SSPEC_RESOURCE_XMEMFILE("/rabbit1.gif", rabbit1_gif)
SSPEC_RESOURCETABLE_END
That concludes the Rabbit side of your question. Next you should look at the STATIC.HTML page located in the C:\DCRABBIT_XX.XX\Samples\TCPIP\HTTP\Pages directory.
Within the body of your web page you will need to use this HTML code to display the rabbit.gif file correctly in your web page:
<img SRC="rabbit1.gif">
With that you should have no issue using a .GIF file.
Using a .JPG file is very similar, but instead your MIME table will use:
SSPEC_MIME(".jpg", "image/jpeg")
The MIME table is an internet standard and you can find more information by googling MIME and the file type you wish to use.
For example googling ".tif" and “MIME” brings you to this page of common MIME types: http://www.w3schools.com/media/media_mimeref.asp
For more specific information on the Rabbit Web Server, look at the TCP/IP User's Manual Volume 2 - Chapter 4.
You can include a wide range of different file types including cascading style sheets, JavaScripts, XML, and more. If you are interested in more information about Embedded Web Development, you might listen to the recorded seminars created by Puck Curtis who is one of the engineers responsible for providing developer support.
Here is a link to our online seminar series: http://www.digi.com/news/videos.jsp
- Larry C.
Larry Cicchinelli is Rabbit’s Technical Support Manager. He has 30 years of embedded experience, and is considered one of the foremost authorities on Rabbit products. Larry and his staff offer comprehensive technical support to Rabbit customers.
Submit your questions for Larry via email at AskLarry@rabbit.com
Read more Ask Larry Answers
