Displaying image/files in a browser

Coordinator
Jan 17, 2013 at 4:47 PM

I'm using this code and wondering if there is a better approach of showing a file in a browser.

*-- raw file name
lsfullfilename = 'C:\image\sampleimage.tif'

*-- construct web friendly path/file name
sourcefile =lsfullfilename   
newext = ""
newext = JUSTEXT(sourcefile)

*-- create a dummy file name (assumes the TEMP folder exist in the root folder)
lsrandfilename = oSession.VALUE("chart") + SYS(2015)
targetdest =ADDBS(oProp.AppStartPath) + 'temp\' + lsrandfilename + '.' + newext
translatedurl = [http://]+oRequest.ServerVariables("HTTP_HOST") +JustPath(oRequest.ServerVariables("URL"))+[Temp/] + JUSTFNAME(targetdest)

*-- convert the file in a string
lsfilestr = FILETOSTR(sourcefile )

*-- create the file using the dummy filename
STRTOFILE(m.lsfilestr, targetdest)

*-- assign it to an oSession variable
oSession.VALUE("sampleimage", translatedurl)
lcHTMLfile = oSession.VALUE("scandocs1")

*-- Show it in browser
oResponse.Redirect(lcHTMLfile)

Coordinator
Jan 17, 2013 at 6:32 PM

So you're trying to show a chart image from a hyperlink?  It seems like you're doing a lot here.  

You're copying to a temp area because the original location is not web readable??

This looks good assuming you can't just place the image in a web readable folder in which case you would just:

oResponse.Redirect("http://localhost:444/avfp6/temp/IMG_3P00BCSU65212.gif")  &&should work,
Coordinator
Jan 17, 2013 at 7:24 PM
Edited Jan 17, 2013 at 7:26 PM

I think there's a simplified approach on what I'm doing.  Basically the code above works, it's just I think it can be better.

To answer your question

#1 Yes, it's being access thru hyperlinks.  

#2.  Yes, the original location is not web readable.  It can be any folder from the webserver that is why I create a copy of that file in the TEMP folder.  The issue that might arise here is the efficiency on creating the file.  For PDF's as large as 5MB that might actually take a while.

So again, I'm just looking at some other approach on how to do things on this scenario.

Coordinator
Jan 17, 2013 at 8:49 PM

 

"For PDF's as large as 5MB that might actually take a while."

 

You might want to consider running it on a background thread then, instead of interactively.  That way you can give them a status message maybe and a way to cancel out instead of a frozen screen.

Jan 21, 2013 at 8:54 AM
Edited Jan 21, 2013 at 9:04 AM

"#2. Yes, the original location is not web readable"

I used to create a readonly virtual directory linked to the physical directory. If the file exist at the physical directory then i link source and anchor to the virtual directory. The virtual folder can be also a root of folders,

In my case, to work with many folders as a depository for pictures received by ftp, I created and external task (listener) moving  picture files to the virtual directory.