Overview
Features
Download
Documentation
Community
Add-Ons & Services

Image with HTTPserver

A general discussion forum.

Image with HTTPserver

Postby Manu » 05 Aug 2009, 15:26

Hello,

I tried to add an image into the HTML with the HTTPTimeserver sample, but it doesn't work.

See code below, I added img tag:

std::ostream& ostr = response.send();

ostr <<
"<html>\n"
"<head>\n"
"<title>POCO Form Server Sample</title>\n"
"</head>\n"
"<body>\n"
"<h1>POCO Form Server Sample</h1>\n"
"<h2>GET Form</h2>\n"
"<img src=\"/myImage.png\" height=\"267\" width=\"400\" />\n" "<form method=\"GET\" action=\"/form\">\n"
.
.
.


The question is : How to make that?
Manu
 
Posts: 1
Joined: 05 Aug 2009, 15:11

Re: Image with HTTPserver

Postby guenter » 06 Aug 2009, 06:49

You need to add a request handler for the image that sends back the image file.

In the simplest case, you add a request handler which simply does a

Code: Select all
response.sendFile("myImage.png", "image/png");


and add the following code to your request handler factory:

Code: Select all
if (uri.getPath() == "/myImage.png")
   return new MyImageHandler;


If you have to serve lots of different images and style sheets, etc., however, you might want to implement this in a generic way. In this case you need to implement a translation from URI paths to filesystem paths (take care of ".." path segments in the URI and trailing "." in the filesystem on Windows) and a mapping from file name extensions to MIME types.
guenter
 
Posts: 1153
Joined: 11 Jul 2006, 16:27
Location: Austria


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest