how do you use RegisterFileLocation procedure from fpWebFile.pp? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Awesome Programmer · 2013-07-22 19:42 After working through my threaded http webserver program, now I am running into a different problem. I want to be able to point the http server application to a virtual folder which points an actual path on the hardrive. From what I read RegisterFileLocation procedure should let you do exactly that. So, after putting my code as follows, I try to access my webpage, but I can't see the image that supposed to display in the browser. RegisterFileLocation('files','/home/reltek/fcl-web/threaded_http'); I try to access the image as follows; http://192.168.1.117:8080/files/myscree.jpg All it displays is a broken icon to indicate broken image link. So, whats my problem? thanks for your help. ---------------------------------------------------------------------- Leledumbo · 2013-07-22 21:41 Probably wrong mimetype, which defaults to application/octet-stream. Set MimeTypesFile to path to a file containing mimetypes definition at the start of your program (or at unit initialization). ---------------------------------------------------------------------- Awesome Programmer · 2013-07-23 12:39 How is about the following code? Is that sufficient? Code: [Select]Procedure TForm1.Create; begin      RegisterFileLocation('files','/home/reltek/fcl- web/threaded_http');      MimeTypesFile := '/etc/mime.types'; end; Here is the HTML page Response from the HTTP server. Code: [Select]procedure TForm1.DoHandleRequest(Sender: TObject;  var ARequest: TFPHTTPConnectionRequest; var AResponse: TFPHTTPConnectionResponse); begin          AResponse.Content:='Oh Venus, Oh Venus, Oh VenusTesting'+ARequest.URL+          '
'; end; I still don't see the image but I do see the text. ---------------------------------------------------------------------- Leledumbo · 2013-07-23 15:41 And what happens if you view source and click the image link directly? ---------------------------------------------------------------------- Awesome Programmer · 2013-07-23 15:50 Here is what I see. Take a look at my attached image. I am using FireFox. As you can see, I can see everything except the image. UPDATE: just as a test, I hot linked an image directly from our company's website webserver and it worked. Only when I say,Code: [Select] /files/myscreen.jpg orCode: [Select] http://192.168.1.117:8080/files/myscreen.jpg from Lazarus' HTTP webserver it doesn't work. So, what is the difference here? ---------------------------------------------------------------------- Leledumbo · 2013-07-23 21:29 QuoteI hot linked an image directly from our company's website webserverDo you mean it points to image in an external server? It would be totally different since the web browser will query the external server instead of your application. Try the attached project (don't forget to adjust the path in .lpr), and ensure you get the same result (HTTP 200 OK) in your browser's developer tools (screenshot attached). At the worst, your browser should download the image instead of displaying it. ---------------------------------------------------------------------- Awesome Programmer · 2013-07-24 13:39 Thanks for the sample project. I got it debugging, but when I request the page from your sample http server I get the following errors. See the attached image. Am I doing this right? ---------------------------------------------------------------------- Leledumbo · 2013-07-24 17:01 Ah, sorry. I forgot to mention the URL: http://:8080/index/main ---------------------------------------------------------------------- Awesome Programmer · 2013-07-24 17:58 I am almost happy. I ran your program and send a request out just as you said and I got an error on the server. See the image. However, when I clicked on the "Continue" button and the error box popped up again, but this time I noticed that HTTP server did send the HTML page and the image. Your image was displayed on the browser. Any idea? ---------------------------------------------------------------------- Leledumbo · 2013-07-25 05:05 Yes, the exception is intended and is part of fpweb flow. Don't worry, it's internally handled and your actual code won't have any exception, it's the debugger that currently still catches exception regardless it's handled or not. ---------------------------------------------------------------------- Awesome Programmer · 2013-07-25 14:18 yea. I just ran your compiled program by itself outside of Lazarus IDE and it ran without any error messages. Plus, it served the webpage with your image. Now, I have a working test program to learn and work from. Thanks. I still can't get my GUI Application with http server to display an image but it does respond with html texts. So, What is the difference between your test program and mine? I see that your program is a http application that uses modules to respond to client request(s). My program is an GUI Application, which runs HTTP server from within an inherited Thread Class and I am not using modules to respond to client request. Correct me if I am wrong. ---------------------------------------------------------------------- Leledumbo · 2013-07-25 15:05 QuoteMy program is an GUI Application, which runs HTTP server from within an inherited Thread Class and I am not using modules to respond to client request.In that case, I have no idea. Both utilizes the same style of program initialization (Application.Initialize followed by Application.Run) though http server app is not a LCL app. Application.Run will run forever (until terminated actually) thus you can't really execute Run method from 2 different Application instance. RegisterFileLocation is designed to work with fpweb modules. Just open the code and see yourself what the code really does.