Page 1 of 1

Using a FUNCTIONCALL to display an image?

Posted: Thu Jul 22, 2010 6:22 am
by mokie
Hello,

I'm trying to do a proof of concept of loading an icon from an FTP server and display that on a page. Currently I'm using a .gif, but if it turns it some other image format is better to do this, so be it. I'm using a functioncall on a html page, and reading the image from FTP then attemping to use writestring to output it. The current result is it just prints "GIF89a" (which is at the beginning of any gif, it seems the FTP won't read past that because of the funky characters after the GIF89a). I'm pretty sure I'm doing a few things fundamentally wrong, so if I'm totally off, could you describe the procedure and the Netburner library functions I could use to display the image loaded from FTP?

Here's the code:

Code: Select all

void WriteIcon(int hSocket, PCSTR szUrl)
{
	char tmp_resultbuff[2000];
	
		int iSession = FTP_InitializeSession(
									AsciiToIp("IPHERE"),
                                    21,
                                    "username",
                                    "password",
                                    600);
                                    
    FTPSetDir( iSession, "DIRECTORYOFICONHERE",  100 );
                                    
	// Setup file transfer and get file descriptor fdr
	int fdr = FTPGetFile( iSession, "Kitty.GIF", FALSE, 100 );
	if (fdr > 0)
	{
		// The following function reads data from the specified file until complete.
		// This is the location where you could use
		// a different mechanism to retrieve the data.
		//iprintf( "\r\n[" );
		int rv;
		//SendGifHeader(hSocket);
		do
		{
			rv = ReadWithTimeout(fdr,tmp_resultbuff,sizeof(tmp_resultbuff),20);
			if (rv < 0)
				iprintf("RV = %d\r\n",rv);
			else
			{
				tmp_resultbuff[rv] = 0;
				iprintf("%s",tmp_resultbuff);
				
			}
		} while (rv > 0);
		writestring(hSocket, tmp_resultbuff);
		//iprintf("]\r\n");
		close( fdr );
		// Now read the command result code from the GetFile command
		rv = FTPGetCommandResult( iSession, tmp_resultbuff, 255, 100);
		if (rv != 226)
			iprintf("Error Command result = %d %s\r\n", rv, tmp_resultbuff );
	}
	else
	iprintf( "Failed to get file FOOBAR.TXT\r\n" );
	// This function reads the data stream from the fd and
	// displays it to stdout, which is usually the com1 serial
	// port on the NetBurner board.

	FTP_CloseSession(iSession);

}

Re: Using a FUNCTIONCALL to display an image?

Posted: Thu Jul 22, 2010 9:57 am
by pbreed
The problem is that your functioncall is probably hapening in an html page.
The sever has already told the client to expect an html page not a gif.
You need to intercept the get request earlier and send a gif header telling the clinet (browser) that what you are sending is a gif and not an html page.

Take a look at the example nburn\examples\wem\bagraph this is doing almost exactly what you want.
(The only real difference is that the gif is internally generated not externally sourced)

Paul