Home     Products      Support      Corporate     Sign In 
Support Knowledge Base, Article 1100
Product
FileUp
Version
5.x
Title
Display an inline image in a webpage using FileUp
Problem
Can FileUp be used to display an image in an <img> tag within a webpage?
Solution

Yes. Since a download using FileUp writes a file directly to the response object, an image streamed by FileUp can act in the same manner as a statically linked image in a webpage. An an img tag, you simply replace the path of a static image with the path of a page that uses FileUp to download an image.

For example, if a webpage had the following img tag:

<img src="sample.jpg">

you could replace the src value with a webpage that uses FileUp to download any image. If the image to load will be dynamically determined on the server then a querystring parameter can be used:

<img src="DownloadImage.asp?ID=1">

The DownloadImage.asp page would then retrieve an image based on the querystring parameter and stream it to the response object -- (this is based on our Open In Place Download sample):

<%@ Language=VBScript %>
<% Option Explicit 

'--- Declarations
Dim oFileUp
Dim strFilePath
Dim strFileName
Dim oFM, oFile

'--- Instantiate the FileUp object
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")

'--- Do image path and filename lookup (from database fields or other server-side code)
If Request.QueryString("ID") = 1 Then
	strFilePath = Server.MapPath("sample.jpg")
	strFileName = "sample.jpg"
End If

'--- Use SoftArtisans.FileManager to obtain the byte-size of the file
'--- and set it in the Content-Size header
On Error Resume Next
	Set oFM = Server.CreateObject("SoftArtisans.FileManager")
	If Err.Number <> 0 Then
		Response.Write "<B>Error creating FileManager object.</B> FileManager must " & _
						"be installed for this sample to run."
		Response.End
	End If
On Error Goto 0

On Error Resume Next
	Set oFile = oFM.GetFile(strFilePath)
	If Err.Number <> 0 Then
		Response.Write "<B>FileManager could not open the file at:</B> " & strFilePath & _
						"<BR>" & Err.Description & " (" & Err.Source & ")"
		Response.End
	End If
On Error Goto 0	
	
'--- Set response headers
'--- Set the ContentType as appropriate
Response.ContentType = "image/jpeg"

'--- Set Content-Disposition to "inline" and specify the filename.
Response.AddHeader "Content-Disposition", "inline;filename=""" & strFileName & """"
Response.AddHeader "Content-Length", oFile.Size
	
'--- Send the file
On Error Resume Next
	oFileUp.TransferFile strFilePath
	If Err.Number <> 0 Then
		Response.Clear
		Response.Write "<B>FileUp could not download the file at: </B> " & strFilePath & _
						"<BR>" & Err.Description & " (" & Err.Source & ")"
		Response.End
	End If
On Error Goto 0
	
	
'--- Clean up
Set oFile = Nothing
Set oFM = Nothing
Set oFileUp = Nothing
Response.End
%>

Additional code samples in C# and VB.NET are attached to this article.

Attachments
Attachments/KB1100_files1.zip
Created : 6/30/2005 6:10:01 PM (last modified : 6/30/2005 6:10:01 PM)
Rate this article!
Comments