Displaying local image in web file

Started by Jeff, June 26, 2019, 08:36:44 AM

Previous topic - Next topic

Jeff

Hi all!

When I am displaying a jpg or png file in my browser using the url path to the image it is fine. I can open and view a local image file through my browser just fine.

When I attempt to display a local image file veiwing a .web file, I get the typical image encoding. Not the rendered picture.

Is there a way to render the picture? Any suggestions is helpful.

WebOut( 'Content-type: text/html', 2) ; Output HTML Context type
WebOut( '<html> <head> <title>Display File Attachment Download</title> </head> <body>', 1)
WebOut("Server side image displays fine!<br>",1)
WebOut('<img alt="/webcgi/kb/pix/MyImage.jpg" height="80" SRC="/webcgi/kb/pix/MyImage.jpg" width="80" />',1)
WebOut("<br>",1)
USERNAME = ItemExtract(2,Environment("REMOTE_USER"),"\")
DefaultDownloadFolder=StrCat("C:\Users\",USERNAME,"\Documents")
WebOut("Client side image not pretty!<br><br>",1)
WebOut(StrCat(DefaultDownloadFolder,"\MyImage.jpg<br>"),1)
WebOutFile(StrCat(DefaultDownloadFolder,"\MrImage.jpg"))
WebOut('</body>',1)
WebOut('</html>',1)


Jeff

td

Please review the Stones.web file in the Stones folder of your WebBatch installation.  The script contains an example of how to display an image in HTML output.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Jeff

Thanks for the quick response. I may not be explaining myself very well.

After saving a jpg or png or even a pdf to my local computer I am then trying to open in the same browser session. When I try your suggestion....

1. The GIF file must be in the current directory. If I am working within the current directory structure, I can simply: WebOut('<img alt="" height="80" SRC="/webcgi/kb/pix/MyImage.jpg"" width="80" />',1.
 
2. Dumpgif displays the specified .GIF file in a browser. When I try a jpg, I get the error "WebBatch Error: File does not have an extension of '.GIF'".
Jeff

td

Do you understand the purpose of WebBatch?  It is a CGI scripting tool and must be executed from a Web server.  To view an image using WebBatch you would need to use a browser to connect to the Website running WebBatch using a URL.  The communication process is handled via the HTTP protocol.  Any client-side file system access is handled by the client software not WebBatch server software.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Jeff

Jeff

td

It is not clear that this is what you are trying to do but if you want to get a browser to download a file, you need to use the proper HTTP entity headers.  More specifically you need to WebOut a 'Content-type' header and a 'Content-disposition' to tell the browser the type of file and what you suggest the client do with it - like save it to the file system before calling WebOutFile.  You can use the "Content-type" header without the "Content-disposition" to instruct the browser to display the image without saving it to the client file system.  A quick Web search on those HTTP headers can provide the needed details.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Jeff

If you look in my original post, I have a sample script. It looks like the web browser security is stopping it. 
Jeff

td

If you read the previous post carefully, you will notice that your "simple" script does not follow the recommendation to set the necessary and appropriate HTTP headers before attempting to output a file.   Your original script is not going to work as posted security or no security problem. 

Also, remember that a WebBatch script runs in the context of the WebServer.  If you are using IIS, this means the script is running with the security context of a restricted user account.   As such your script can only access system resource like file system locations that a restricted user can access.  IIS can impose additional restrictions on the IIS user based on IIS settings.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

A three liner that works with at least one browser:
Code (winbatch) Select
WebOut("Content-type: image/bmp",1)
WebOut("Content-Disposition: inline", 2)
WebOutFile('e:\test\test.bmp')
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Jeff

First and foremost I am sorry to be a nuisance.

My overall goal is to build a knowledge base website to replace an existing phat client using the same SQL database. Inserting text strings have not been a problem, but handling images associated with the kb articles have been. In some way, I need to make images savable and viewable. And no, I am not a real developer but I have stayed at a holiday inn once or twice. 

After getting my test server <another physical web server>, I see what you are referring to as server side versus client side. I understand that the server runs the .web file using the webbatch executable server side and the client sees the rendered html. Not the actual web file.

Since moving some of my pages to different IIS server other than my local computer, when I save a file via the web browser it remains on my profile stored on the server. DefaultDownloadFolder=StrCat("C:\Users\",USERNAME,"\Documents")  and not on my local station. This is also why I can't open the file locally.

I know there has to be a way to upload and download files and render them locally. If you have any simple references or examples to point me to, I would appreciate it.

Thanks.
Jeff

JTaylor

Not sure if I want to get in this conversation or not but here goes  :)  ....

Are you wanting the data and images residing on your server or locally?   You keep mentioning that you want to render things locally but then talk about a KB website.   It might help if you briefly list the steps, in order, you need to take to accomplish your goal as I, also, am still not sure what you want to do exactly.


Jim

Jeff

TD - If you want to close this thread, please do. I don't think it will help anyone.
Jeff