The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Classic ASP - Concurrent Downloads of Binary Large Files

Banging my head against this problem for a while, I figure this must be a solved problem though.  I'm trying to send binary files, doing something like:

    Response.ContentType = "application/x-unknown"
    fn = "whatever.jpg"
    FPath = "c:\" & fn
    Response.AddHeader "Content-Disposition","attachment; filename=" & fn
    Set adoStream = CreateObject("ADODB.Stream")
    adoStream.Type = 1
    DO WHILE NOT objStream.EOS
    Response.BinaryWrite objStream.Read(10*1024)
    Set adoStream = Nothing

This works fine.  Except that the server queues up downloads so that only one is running at a time, which is a problem as the files are huge and take a while to download.  i.e. it looks like the file is being locked when it's open.  I've also tried setting adoStream.mode to adModeRead and some others with no luck.  What's the trick I'm missing here?  Or is there a much better way to do this (other than direct downloads, which aren't an option)?
Tuesday, October 18, 2005
Mike Johnson Send private email
Tuesday, October 18, 2005
hmm.. forget that, those don't control access and stream the output.

You'll either need to cache the file (say in SQL) in a way that allows multithread access, or  use Msxml2.XMLHTTP or similar to connect to your webserver, grab the file, and then stream out the contents

Just for an idea, here's a vb sample I found on google.

var adoStream = new ActiveXObject("ADODB.Stream");
adoStream.Charset = "iso-8859-1";
adoStream.Type = adTypeBinary;

var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
xmlHTTP.Open("GET", url_to_download);

Mike Johnson Send private email
Tuesday, October 18, 2005

Won't the above read the file into memory?  That's partly what I'm trying to avoid, since the files are say 40 Meg, so it wouldn't take many downloads to be out of RAM.

I guess what I need is to able to open the file with ADO.Stream in a way that other ADODB.Stream objects can read from it at the same time... but the read only mode doesn't seem to do that like i thought it would.
Tuesday, October 18, 2005
Or write a component in Delphi or .Net to do exactly what you need. I have a feeling that you are being bitten by a hidden feature of the stream object.
Mike Johnson Send private email
Wednesday, October 19, 2005

This will not give you correct results for binary data...
I tried once to download a zip file using xmlHTTP and was unable to get the full contents of the zipfile using xmlHTTP.responseBody atleast in Scripting languages like Javascript and VBscript that don't handle binary data well.

This approach would work fine in C++ though, if you use ISAPI.
Julius Gray
Thursday, October 20, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz