Force Save As prompt, BinaryWrite ?

Hi all,

Sorry if this is real newbie stuff, hopefully you can provide me with directions on were to go from here.
I've created a directory browsing code which works without any problem.
The problem is that when a user (or me, still in development) tries to download a file it opens the file in the browser, instead of having the Save As prompt.
So I want to force the Save As prompt.
So I searched the net and found that this was possible, I found a good example using the Response.BinaryWrite method. The problems with BinaryWrite is that it doesn't handle big files very well (AFAIK).

I read on msdn that the default buffer size is 4MB.
I guess this i right because I get "virtual memory" errors on the server if I try to download a 50MB file.
So is this fixable ?

Here is the example code from www.aspfaq.com:

<%
    fn = "ml1.jpg"
    FPath = "c:\" & fn
    Response.ContentType = "application/asp-unknown" ' arbitrary
    Response.AddHeader "content-disposition","attachment; filename=" & fn
    Set adoStream = Server.CreateObject("ADODB.Stream")
    adoStream.Open()
    adoStream.Type = 1
    adoStream.LoadFromFile(FPath)
    Response.BinaryWrite adoStream.Read()
    adoStream.Close: Set adoStream = Nothing
    Response.End
%>

I've modified the code so that it's checking the path and file name that get send from the link.
Otherwise it's the same code.
LVL 1
BlarpieAsked:
Who is Participating?
 
apolloisConnect With a Mentor Commented:
Hi Blarpie,

Two thoughts:

     1.     Usually files of significant size are compressed using something like PKZIP/WINZIP before downloading.  If you convert your large docs to .zip, then the normal IIS download will work fine.
     2.     If you have a lot of files to download, and of significant size, then you may need a commercial download component that can handle large file sizes and resumable downloads.

Here's one example:

SoftArtisans FileUp 4.0
http://fileup.softartisans.com/default.aspx?PageID=131
FileUp also includes file download and file management controls, which allow you to simply and easily download files from the Web server to the user's browser, manipulate files, change ACLs and permissions, and register DLLs, all in a single, easy-to-use package.



Best Regards,
>apollois<
0
 
hongjunCommented:
How about trying using FileSystemObject method?

<%
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile("C:\yourfile.jpg")

Response.Buffer = True

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-disposition", "attachment; filename=yourfile.jpg"

Do While Not objTS.AtEndOfStream
   strChunk = objTS.Read(32)
   strTmp = "" 
   For i = 1 to Len(strChunk)
       strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
   Next
   Response.BinaryWrite strTmp
   Response.Flush
loop

objTS.Close
Set objTS = Nothing
Set objFSO = Nothing
%>


Not sure if it works for 50MB file. Try it out.

hongjun
0
 
sybeCommented:
basically the ADODB.Stream method should be a lot better. Except that you have a memory problem on the server with large files. That is not because of the method used, but because of hardware limitations.

Have you tried this one (not sure it will work..)

<%
Response.ContentType = "application/octet-stream"
Response.redirect "yourfile.jpg"
%>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
BlarpieAuthor Commented:
Thanks for the responses, I'll try each and see if that fix the problem.

Apollois, the only problem with FileUp as I see it, is that it's overkill for my purpose/plan.
But I'll check it out.
0
 
BlarpieAuthor Commented:
Ok, when I tried to use the FileSystemObject I didn't get a memory problem but it shut down the download after about 13MB and the transfer rate was 100KB/s on a 100Mb LAN. So it may not be the best thing or it's the same symtom but displayed differently.

The redirect thing doesn't work in my case unless I move the fileshare-directory within the web-structure.
But that may be the easiest way around the problem because then people can use "right-click" if they want to download the file.

0
 
BlarpieAuthor Commented:
It seemed like there was no easy/cheap way to get the functionality were I wanted so I accept Apollois answer directing me to a commercial solution.
Thanks guys.
0
 
apolloisCommented:
Blarpie,

Thanks for selecting my comment as the answer.  But why the grade of "B"?

I thought I had answered your question completely and correctly.  Is there any directly related information that you need to answer the original question?

Please see How Do I Know What Grade to Give?
http://www.experts-exchange.com/cmtyQuestAnswer.jsp#3

If you wish to change the grade, you can post a zero-point question with Community Support (http://www.experts-exchange.com/Community_Support/qAskQuestion.jsp).  Include a link to this question, and the new grade.

Best Regards,
>apollois<
0
 
BlarpieAuthor Commented:
Sorry, haven't been here in a while and you are correct.
Posted the correction to the community support.

Rgds
Blarpie
0
 
YensidModCommented:
Grade change to an A.

YensidMod
EE Moderator
0
All Courses

From novice to tech pro — start learning today.