Hi,
I've build an embedded web-server using snorkel, which receives some sort of data from the client, in order to generate a QR code.
the QR code (which is saved as an image)must be displayed on the client-side to be captured by the client.
The problem is I cant display it!
I've used the HTML code within the embedded server as follow:
<html>
<body>
<img src = QR.jpg>
</img>
</body>
</html>
All I get is a small box with an X inside of it.
And this is my C++ code:
#pragma hdrstop
#pragma argsused
#include <snorkel.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
call_status_t index_htm(snorkel_obj_t http,
snorkel_obj_t outstream)
{
if (snorkel_printf (outstream, "<html><body><img src=QR4.jpg alt=QRcode width=178 height=178>" "</img></body></html>\r\n")== SNORKEL_ERROR)
return HTTP_ERROR;
return HTTP_SUCCESS;
}
void syntax (char *pszProg)
{
fprintf (stderr, "syntax error:\n");
fprintf (stderr, "%s [-p <port>]\n", pszProg);
exit (1);
}
void main (int argc, char *argv[])
{
int i = 1;
int port = 8888;
snorkel_obj_t http = 0;
char szExit[10];
for (; i < argc; i++)
{
if (argv[i][0] == '-' || argv[i][0] == '/')
{
char carg = argv[i][1];
switch (carg)
{
case 'p':
port = atoi (argv[i + 1]);
i++;
break;
default:
syntax (argv[0]);
break;
}
}
}
if (snorkel_init () != SNORKEL_SUCCESS)
{
perror ("could not initialize snorkel\n");
}
http = snorkel_obj_create (snorkel_obj_server, 5,
NULL );
if (!http)
{
perror ("could not create http server\n");
}
if (snorkel_obj_set (http,
snorkel_attrib_listener,
port,
0 )
!= SNORKEL_SUCCESS)
{
fprintf (stderr, "could not create listener\n");
snorkel_obj_destroy (http);
}
if (snorkel_obj_set (http, snorkel_attrib_uri, GET, "/index.html", encodingtype_text, index_htm) != SNORKEL_SUCCESS)
{
perror ("could not overload index.html");
snorkel_obj_destroy (http);
}
if (snorkel_obj_set(http, snorkel_attrib_ipvers, IPVERS_IPV4, SOCK_SET) != SNORKEL_SUCCESS)
{
fprintf (stderr, "error could not set ip version\n");
}
fprintf (stderr, "\n\n[HTTP] starting embedded server\n");
if (snorkel_obj_start (http) != SNORKEL_SUCCESS)
{
perror ("could not start server\n");
snorkel_obj_destroy (http);
}
fprintf (stderr, "\n[HTTP] started.\n\n"
"--hit enter to terminate--\n");
fgets (szExit, sizeof (szExit), stdin);
fprintf (stderr, "[HTTP] bye\n");
snorkel_obj_destroy (http);
exit (0);
}
And I've just read that to display an image in HTML, we must convert the image into DATA URL (BASE64), and there are a lot of online converter sites that does that. But the problem is that my project does not use a static QR code, it generates different QR codes with each client. Plus, the size of my image is way larger than the images displayed by these online converters.
So, is there any way I can convert these images into DATA URI (BASE64) programmatically using C++?
Or is there any way I can display my QR code without converting it?
I've been struggling with this problem for few month now, Please need help!
Best Regards.
Rania