1
votes

I'm working on STM32. I'm trying to build a web server based on STM32. First, I implement a file system on SPI flash and write it to the browser with LWIP Libraries. Everything work fine with a html file without any "src". Now i want to add images on web page which means i need to have images on my SPI flash as well. I guess i should format the image first before i store it? and if it is stored in SPI flash. how html use the image? anyone has idea about it?

if ((buflen >=5) && (strncmp(buf, "GET /", 5) == 0))

  {

      FileNodeId = Find_File_Node(WEBPAGE);
      if(Load_File_Table() != VAT_SUCCESS) return VAT_UNKNOWN;
      else{
          for(int i = 1;i <= File_Table[FileNodeId].numSector;i++){

              READSector(WEBPAGE,&webbuf[0],i);
              int html_length=strlen(&webbuf[0]);
              netconn_write(conn,&webbuf[0], html_length, NETCONN_COPY);
              memset(&webbuf[0],0,4080);

          }
      }
      netbuf_delete(inbuf);


  }

This is how I write my html page to the web browser with LWIP Lib. And the html is stored in link listed flash file system.

1

1 Answers

0
votes

Nothing special.

When browser load html page it parse whole tree of objects. Objects of images presents with url to image.

<img src="url_path/image_name.png"/>

Then browser load each image in separete request. So your server will get request with image path for each one and must return right http package with image without any additional formats. As you return image, your package must content corresponding headers:

Content-Length: image_len_in_bytes
Content-Type: image_media_type

There image_media_type can be image/gif, image/png, image/jpeg, image/bmp, image/x-icon or may be another if you will use.

So you have enough code for send any images, just change content type.