related sites: <FREE Help> <ASP> <Asp.net> <worldwide> feedback: <lovethat> <hatethat> <thanks> <credits> <contact us>
Best way to upload files <Next>
Date: Wed, 22 Apr 1998 11:47:15 -0400 From: Richard Walker <Richard.Walker@west-server.com> Organization: West Engineering Subject: [asp advanced] Reading Binary Files
I want to be able to retrieve a binary file from the web server's hard drive (GIF/DOC/PDF/etc) and stream it to the client. I see that there are facilities to do this with text files, but is there any way to do it with binary files? I'd like to be able to do it without creating an ActiveX dll, since the server is 64 bit (Alpha) and its tough to find dll's for that platform.
From: Richard Birkby <RBirkby@3s.co.uk> Subject: RE: [asp advanced] Reading Binary Files Date: Wed, 22 Apr 1998 17:26:19 +0100
You can write a little VB5 DLL, as VB5 now supports Alpha.
We've got something that does XXX.asp?ID=5
which checks a database for the primary key 5, then finds which BMP that references, then converts it to a JPEG, then spits it back out chunk at a time through the blob output facilities of ASP.
Richard
From: David Wihl <wihl@softartisans.com> Subject: RE: [asp advanced] Reading Binary Files Date: Wed, 22 Apr 1998 12:45:59 -0400
In addition to the previous comment about VB5 supporting Alpha, which is completely correct, SA-FileUp has an Alpha version. It includes file upload and download capabilities and is written in VC++. http://www.softartisans.com
For sample VB5 code to do this, search www.microsoft.com for "softgoods" or sgdldsvc.exe
From: David Wihl <wihl@softartisans.com> Subject: RE: [asp advanced] Reading Binary Files Date: Wed, 22 Apr 1998 12:55:12 -0400
The URL is http://www.microsoft.com/isn/techcenter/configuration/commercetools.asp (search for softgoods, not softgood)
Date: Wed, 22 Apr 1998 14:19:42 -0400 From: Richard Walker <Richard.Walker@west-server.com> Organization: West Engineering Subject: Re: [asp advanced] Reading Binary Files -- Solution
I found a great, inexpensive way to do what I wanted to do:
-- begin file -- <% response.ContentType = "image/gif" %> <!-- #include virtual="/images/westlogo1.gif" --> -- end file -- That's all there is to it. No extra components needed!
From: David Wihl <wihl@softartisans.com> Subject: RE: [asp advanced] Reading Binary Files -- Solution? Date: Wed, 22 Apr 1998 20:30:06 -0400
That's fine if all you want is westlogo1.gif all the time, but what if you wanted to change the location via scripting? When using an #include, you must hardcode the filename. Why go through ASP at all, when you could just send the GIF as is? If you're worried about protecting the image, the user could still always right-click on the image and do a "Save As". So, I guess I'm missing the point here...
-David
Date: Thu, 23 Apr 1998 10:37:19 -0400 From: Richard Walker <Richard.Walker@west-server.com> Organization: West Engineering Subject: Re: [asp advanced] Reading Binary Files -- Solution?
David Wihl wrote:
> That's fine if all you want is westlogo1.gif all the time, but what if > you wanted to change the location via scripting? When using an #include, > you must hardcode the filename. Simple solution to this: Open the said asp file via FileSystemObject, generate it at runtime, and write the include directive of the file to be included into the file. Then, load the file. voila, you have an implementation of dynamic includes.
> Why go through ASP at all, when you could just send the GIF as is? If > you're worried about protecting the image, the user could still always > right-click on the image and do a > "Save As". So, I guess I'm missing the point here...
The point is that our images, etc may be in directories which we don't want accessed from the www. On the server side, we have facilities to include these files into documents accessible from the web. I'm not concerned about protecting the images from being copied... after all, the user has already downloaded the image when they view it.
From: David Wihl <wihl@softartisans.com> To: "'asp@mail.mailexperts.com'" <asp@mail.mailexperts.com> Subject: RE: [asp advanced] Reading Binary Files -- Solution? Date: Thu, 23 Apr 1998 11:07:27 -0400 X-Mailer: Internet Mail Service (5.0.1458.49) Precendence: bulk Sender: asp-owner@mail.mailexperts.com Reply-To: asp@mail.mailexperts.com Wow. Seems like a lot of trouble to go through when there are free unsupported, and inexpensive commercially supported alternatives.
Some items to take into account:
Another possibility for you is store the images in database BLOBs. That way the images are protected from WWW access, you can dynamically generate the content, and you don't have to generate extra ASP files.
See the below sample ASP from Microsoft: <% @ LANGUAGE=VBScript %> <% Option Explicit %> <!--#include file="adovbs.inc"--> <% ' This sample utilizes the Image field in the PUB_INFO table. ' This table is installed with Microsoft SQL Server in the ' PUBS database. Dim oConn Dim oRs Dim Pic Dim PicSize ' Setup HTTP Header Information so that the browser interprets ' the returned data as a gif graphic file. Note that browsers ' interpret returned information using MIME headers -- not file ' extensions. Response.Buffer = TRUE Response.ContentType = "image/gif" ' Create ADO Connection Object. Use IISSDK OBDC Souce with ' default sa account and no password Set oConn = Server.CreateObject("ADODB.Connection") oConn.Open "DSN=LocalServer;UID=sa;PWD=;DATABASE=pubs" ' Query SQL to obtain recordset containing gif BLOB Set oRs = oConn.Execute("SELECT logo FROM pub_info WHERE pub_id='0736'") ' Obtain local variable of GIF PicSize = oRs("logo").ActualSize Pic = oRs("logo").GetChunk(PicSize) ' Write Data back to client. Because MIME type is set to ' image/gif, the browser will automatically render as picture Response.BinaryWrite Pic Response.End %> -David
From: "Steve Nicholls" <Big.Steve@btinternet.com> Subject: Re: [asp advanced] Reading Binary Files -- Solution? Date: Thu, 23 Apr 1998 21:05:52 +0100
David,
If you are reading in the file using the file system object there is no need to write it out again as an include file you can just do a ReadAll and then do a Response.BinaryWrite Pic in the same way as your BLOB example. In fact rather than store images in BLOBS you get a performance increase if you store the image file as a physical file on the server and just store a path to the image in the database (though you do need to keep the two in sync of course)
To have the same file handle different images you just need your ASP to handle a querystring parameter, either containing the filename itself or whatever variables are required e.g
Source Doc
<IMG SRC="showimage.asp?imageindex=1"> <IMG SRC="showimage.asp?imageindex=2">
Then in showimage.asp the something like the following:
Response.ContentType = "image/gif" fs=CreateObject(Scripting.FileSystemObject) Select Case Request.QueryString(imageindex) Case 1 Set ts=fs.Opentextfile("Image1.gif",ForReading) Case 2 Set ts=fs.Opentextfile("Image2.gif",ForReading) Case Else Set ts=fs.Opentextfile("default.gif",ForReading) End Select strBinaryData=ts.ReadAll Response.Write strBinaryData Response.End
I needed to do something like this a while back to generate custom graphs, I had an ActiveX component generate the image which was then immediately read in as a text stream returned to the client and the temporary file then deleted. The sole reason for this was at the time I could not find a component which would stream the image straight to the client with out the need to first create a physical file on the server. This approach ensured the temporary image files were automatically delete as the same script created and deleted them.
regards, Steve