Images on a Webserver

Hi everybody,

I have a WebServer on a hydra+ and I want to try to put some images inside a html code. I added the image in Resources, but I don’t know how to call the image in html. This is my code


void helloWebEvent_WebEventReceived(string path, Gadgeteer.Networking.WebServer.HttpMethod method, Responder responder)
{
         string pag = "<html><body><h1>Hola Mundo</h1><img src= \"Resources/logo.jpg\"/></body></html>";
         byte[] bytes = new System.Text.UTF8Encoding().GetBytes(pag);
         Debug.Print("Hello world");
         responder.Respond(bytes, "text/html");
}

Thanks in advance

The browser after it receives the page will parse the img tag and request the image file.

you need to realise that you will get TWO requests at approximately the same time, as Cowboy says. First, you will get the HTML page request - and you will respond with the HTML content including the image. Second you’ll get a specific request for the image, and that is the point you need to respond with the image binary contents. So in your current code, the only thing you do is respond with a HTML page. You need to start interpreting the string path that is fed to your handler and responding appropriately.

Thanks.

This is the final code


public partial class Program
    {
        WebEvent helloWebEvent;
        WebEvent logoWebEvent;
        
        ...

        void ethernetENC28_NetworkUp(GT.Modules.Module.NetworkModule sender, GT.Modules.Module.NetworkModule.NetworkState state)
        {
                Gadgeteer.Networking.WebServer.StartLocalServer(ethernetENC28.NetworkSettings.IPAddress, 80);

            helloWebEvent = Gadgeteer.Networking.WebServer.SetupWebEvent("hello");
            helloWebEvent.WebEventReceived += helloWebEvent_WebEventReceived;

            logoWebEvent = Gadgeteer.Networking.WebServer.SetupWebEvent("logo.jpg");
            logoWebEvent.WebEventReceived += logoWebEvent_WebEventReceived;

}
private void logoWebEvent_WebEventReceived(string path, GT.Networking.WebServer.HttpMethod method, Responder responder)
        {
            byte[] bytesimage = Resources.GetBytes(Resources.BinaryResources.logo);
            responder.Respond(bytesimage, "image/jpeg");
        }
void helloWebEvent_WebEventReceived(string path, Gadgeteer.Networking.WebServer.HttpMethod method, Responder responder)
        {
            string pag = "<html><body><h1>Hola Mundo</h1><img src= \"logo.jpg\"></body></html>";
            byte[] bytes = new System.Text.UTF8Encoding().GetBytes(pag);
            responder.Respond(bytes, "text/html");
        }