Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-07

httpWebServer does not show images for some users

6 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

John Repucci

I've been playing around with the httpwebserver and having problems getting it to display images.
see: http://www.lazarus.freepascal.org/index.php/topic,17296.0.html for some history on this.

I've added the project if you care to Reinier or I see the image when we compile the app, but Leledumbo does see the image.

Thoughts? Suggestions?

I'm using Laz 1.1, recent svn's, tested with both 2.6.1 and 2.7.1 - both recently updated, on win32-Vista
Reinier: x86 Laz 1.1 (June 24 svn), FPC 2.6.1 (June 24 svn), Windows Vista x64 Leledumbo: Kubuntu 12.04 & Windows XP SP3, all 32-bit, FPC 2.7.1 r21512, Laz 1.1 r37563M
-------------- next part --------------
A non-text attachment was scrubbed...
Name: httpWebServer.zip
Type: application/zip
Size: 19155 bytes
Desc: not available
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120706/4ceab3b5/attachment-0001.zip>

Reply by email

Michael Van Canneyt
to John Repucci
John Repucci wrote 9 lines
I've been playing around with the httpwebserver and having problems getting it to display images. see: http://www.lazarus.freepascal.org/index.php/topic,17296.0.html for some history on this. I've added the project if you care to look at it. Neither Reinier or I see the image when we compile the app, but Leledumbo does see the image.

I also could see the image, but the URL I had to use is:

http://localhost:8081/img/index.html

The reason for this is that you have 2 modules in your application.

If you do not specify a path, the webserver has no way of determining what module it should invoke. There is a property 'AllowDefaultModule' which will allow to select a default module if no module name is found.

Then, if you have multiple modules, you need to tell the webserver which is the default module to use. You can do this by setting DefaultModuleName.

So, I set up the project file by adding

   Application.AllowDefaultModule:=True;
   Application.DefaultModuleName:='img';
before
   Application.initialize;

and then everything worked fine with the URL:

http://localhost:8081/index.html

Michael.

Reply by email

John Repucci
Show quoted text 49 lines
Message: 2 Date: Sat, 7 Jul 2012 09:31:44 +0200 (CEST) From: Michael Van Canneyt Subject: Re: [Lazarus] httpWebServer does not show images for some users To: Lazarus mailing list Message-ID: Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII On Fri, 6 Jul 2012, John Repucci wrote: > I've been playing around with the httpwebserver and having problems > getting it to display images. > see: http://www.lazarus.freepascal.org/index.php/topic,17296.0.html > for some history on this. > > I've added the project if you care to look at it. > > Neither Reinier or I see the image when we compile the app, but > Leledumbo does see the image. I also could see the image, but the URL I had to use is: http://localhost:8081/img/index.html The reason for this is that you have 2 modules in your application. If you do not specify a path, the webserver has no way of determining what module it should invoke. There is a property 'AllowDefaultModule' which will allow to select a default module if no module name is found. Then, if you have multiple modules, you need to tell the webserver which is the default module to use. You can do this by setting DefaultModuleName. So, I set up the project file by adding Application.AllowDefaultModule:=True; Application.DefaultModuleName:='img'; before Application.initialize; and then everything worked fine with the URL: http://localhost:8081/index.html Michael.

Michael,

After adding the above lines (thank you) and using http://localhost:8081/index.html, I get a blank page (and nothing on the source page). (tested using both FF and Chrome)

The only way I am able to see the expected web page is by using: http://localhost:8081/main/default (still no image).

When I use Application.DefaultModuleName:='main', then going to
http://localhost:8081/ I see the expected page (still no image).

re: Modules - I have two modules? I see the Main module ( RegisterHTTPModule('Main', TMain)), but where is the 2nd module? 'img' is suppose to be the location for my image files. (in this case, in the same directory as the application)

Reply by email

Michael Van Canneyt
to John Repucci
John Repucci wrote 64 lines
> Message: 2 > Date: Sat, 7 Jul 2012 09:31:44 +0200 (CEST) > From: Michael Van Canneyt > Subject: Re: [Lazarus] httpWebServer does not show images for some > users > To: Lazarus mailing list > Message-ID: > Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII > > > > On Fri, 6 Jul 2012, John Repucci wrote: > >> I've been playing around with the httpwebserver and having problems >> getting it to display images. >> see: http://www.lazarus.freepascal.org/index.php/topic,17296.0.html >> for some history on this. >> >> I've added the project if you care to look at it. >> >> Neither Reinier or I see the image when we compile the app, but >> Leledumbo does see the image. > > I also could see the image, but the URL I had to use is: > > http://localhost:8081/img/index.html > > The reason for this is that you have 2 modules in your application. > > If you do not specify a path, the webserver has no way of determining > what module it should invoke. There is a property 'AllowDefaultModule' > which will allow to select a default module if no module name is found. > > Then, if you have multiple modules, you need to tell the webserver which > is the default module to use. You can do this by setting DefaultModuleName. > > So, I set up the project file by adding > > Application.AllowDefaultModule:=True; > Application.DefaultModuleName:='img'; > > before > Application.initialize; > > and then everything worked fine with the URL: > > http://localhost:8081/index.html > > Michael. Michael, After adding the above lines (thank you) and using http://localhost:8081/index.html, I get a blank page (and nothing on the source page). (tested using both FF and Chrome) The only way I am able to see the expected web page is by using: http://localhost:8081/main/default (still no image). When I use Application.DefaultModuleName:='main', then going to http://localhost:8081/ I see the expected page (still no image). re: Modules - I have two modules? I see the Main module ( RegisterHTTPModule('Main', TMain)), but where is the 2nd module?

The file serving module is also a module.

It is 'hidden', as there is no visible data module for you to put components on, but in the background there is a module nonetheless.

'img' is suppose to be the location for my image files. (in this case, in the same directory as the application)

Well, img is the location of all files, including the index.html file ?

Which is why I put it as the default module: it first serves the index.html file (implicitly, because there is no path, and hence the default is used), and then the img file (explicitly, since it's URL starts with /img/).

I used the sources you sent to the mailing list, which I expect to be the same as you are using ?

I cannot do more than explain how it works :-)

Michael.

Reply by email

John Repucci

(Sorry about that - I forgot to change the Subject line.)

John Repucci wrote 20 lines
> The file serving module is also a module. > > It is 'hidden', as there is no visible data module for you to put components on, > but in the background there is a module nonetheless. > >> 'img' is suppose to be the location for my image files. (in this >> case, in the same directory as the application) > > Well, img is the location of all files, including the index.html file ? > > Which is why I put it as the default module: it first serves the index.html > file (implicitly, because there is no path, and hence the default is used), > and then the img file (explicitly, since it's URL starts with /img/). > > I used the sources you sent to the mailing list, which I expect to be the > same as you are using ? > > I cannot do more than explain how it works :-) > > Michael.

re: source - yes I am using the same source files. I removed all of my previous files and used just the contents from the file I supplied plus the additional lines you suggested.

Explanations are good, because I do not have a good idea how this works and there is little documentation on http server application. RegisterFileLocation, AllowDefaultModule and AllowDefaultModule are not found in the chm help files and googling for them does not find anything useful. If any documentation exists, please provide a link. I would love to RTFM ("read the FINE manual").

Assuming that one module is better than two, I removed the RegisterHTTPModule('Main', TMain); &
Application.DefaultModuleName:='main'; lines, but that did not help. I was unable to get the http server to provide anything.

For this simple example, should I have two modules or should I only the default module? If using only the default module is acceptable, how would I use it?

re: the images directory - once I get this working (making an assumption), I want to have all of my images located in a secondary directory and all of my html files in the main (server root) directory.
Eventually: ImageDir := GetCurrentDir + DirectorySeparator + 'image';

Do you (or anyone) have a working example of one or two http server applications, preferable with images on the web page?

Reply by email

leledumbo
to John Repucci
RegisterFileLocation, AllowDefaultModule and AllowDefaultModule are not

found in the chm help files

I'd be surprised if you can find them in the chm since they're undocumented ATM, I'm planning on writing the docs for them. Please wait, since they're part of fcl-web while I'm currently documenting fcl-base.

googling for them does not find anything useful.

At least AllowDefaultModule has explanation here:
http://wiki.freepascal.org/fcl-web#Using_multiple_modules

RegisterFileLocation is not yet there, AFAIR it's quite new addition to fcl-web (at least newer than the wiki page).

Assuming that one module is better than two, I removed the RegisterHTTPModule('Main', TMain); & Application.DefaultModuleName:='main'; lines, but that did not help.

It won't. RegisterHTTPModule(x,y) registers y as a searchable module named x by the web application. This module won't be callable without it. Application.DefaultModuleName is what the web application will use when the given module in URI can't be determined (doesn't exist, etc.).

Reply by email