Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Downloading files of known mime type

Reply
Thread Tools

Downloading files of known mime type

 
 
Bret Thompson
Guest
Posts: n/a
 
      07-08-2005
I am attempting to write an ASP page that will download a file rather then
open it, when it is of known type. I found this code here:
http://mosley.arach.net.au/dev/docs/save%20as.htm

The first example works fine, for files under 5 Mb, the second example
downloads the file but the data is corrupted. Using a JGP file as a
reference, it seems to corrupt the end of the file (since the bottom of the
JPEG is corrupted).

Here is the code I am using. Any idea how to fix this? or an alternative
method?


Response.ContentType = "application/x-unknown"
Response.AddHeader "content-disposition","attachment; filename=" &
Request.QueryString("File")

Set adoStream = CreateObject("ADODB.Stream")
chunk = 2048
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(Server.MapPath(vFilePath))

iSz = adoStream.Size

Response.AddHeader "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClientConnected Then Exit For
Response.BinaryWrite adoStream.Read(chunk)
Next

If iSz Mod chunk > 0 Then
If Response.IsClientConnected Then
Response.BinaryWrite objStream.Read(iSz Mod chunk)
End If
End If

adoStream.Close
Set adoStream = Nothing

Response.End

 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      07-08-2005
What's with the chunks? Perhaps try this code here.

http://www.aspfaq.com/show.asp?id=2161

Ray at work

"Bret Thompson" <Bret http://www.velocityreviews.com/forums/(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am attempting to write an ASP page that will download a file rather then
> open it, when it is of known type. I found this code here:
> http://mosley.arach.net.au/dev/docs/save%20as.htm
>
> The first example works fine, for files under 5 Mb, the second example
> downloads the file but the data is corrupted. Using a JGP file as a
> reference, it seems to corrupt the end of the file (since the bottom of

the
> JPEG is corrupted).
>
> Here is the code I am using. Any idea how to fix this? or an alternative
> method?
>
>
> Response.ContentType = "application/x-unknown"
> Response.AddHeader "content-disposition","attachment; filename=" &
> Request.QueryString("File")
>
> Set adoStream = CreateObject("ADODB.Stream")
> chunk = 2048
> adoStream.Open()
> adoStream.Type = 1
> adoStream.LoadFromFile(Server.MapPath(vFilePath))
>
> iSz = adoStream.Size
>
> Response.AddHeader "Content-Length", iSz
>
> For i = 1 To iSz \ chunk
> If Not Response.IsClientConnected Then Exit For
> Response.BinaryWrite adoStream.Read(chunk)
> Next
>
> If iSz Mod chunk > 0 Then
> If Response.IsClientConnected Then
> Response.BinaryWrite objStream.Read(iSz Mod chunk)
> End If
> End If
>
> adoStream.Close
> Set adoStream = Nothing
>
> Response.End
>



 
Reply With Quote
 
 
 
 
Bret Thompson
Guest
Posts: n/a
 
      07-08-2005
Ray,

Your link is the exact same code at the correct site. Scroll down to the
part that says
"Many people have complained that larger files simply do not work."
And you will see where I got the code with the "Chunks". This is thier
solution for large files.

The first code example fails with files larger then roughly 5 Mb.

Bret


"Ray Costanzo [MVP]" wrote:

> What's with the chunks? Perhaps try this code here.
>
> http://www.aspfaq.com/show.asp?id=2161
>
> Ray at work
>
> "Bret Thompson" <Bret (E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I am attempting to write an ASP page that will download a file rather then
> > open it, when it is of known type. I found this code here:
> > http://mosley.arach.net.au/dev/docs/save%20as.htm
> >
> > The first example works fine, for files under 5 Mb, the second example
> > downloads the file but the data is corrupted. Using a JGP file as a
> > reference, it seems to corrupt the end of the file (since the bottom of

> the
> > JPEG is corrupted).
> >
> > Here is the code I am using. Any idea how to fix this? or an alternative
> > method?
> >
> >
> > Response.ContentType = "application/x-unknown"
> > Response.AddHeader "content-disposition","attachment; filename=" &
> > Request.QueryString("File")
> >
> > Set adoStream = CreateObject("ADODB.Stream")
> > chunk = 2048
> > adoStream.Open()
> > adoStream.Type = 1
> > adoStream.LoadFromFile(Server.MapPath(vFilePath))
> >
> > iSz = adoStream.Size
> >
> > Response.AddHeader "Content-Length", iSz
> >
> > For i = 1 To iSz \ chunk
> > If Not Response.IsClientConnected Then Exit For
> > Response.BinaryWrite adoStream.Read(chunk)
> > Next
> >
> > If iSz Mod chunk > 0 Then
> > If Response.IsClientConnected Then
> > Response.BinaryWrite objStream.Read(iSz Mod chunk)
> > End If
> > End If
> >
> > adoStream.Close
> > Set adoStream = Nothing
> >
> > Response.End
> >

>
>
>

 
Reply With Quote
 
Bret Thompson
Guest
Posts: n/a
 
      07-08-2005
Ray,

Nevermind, I finally found it. There is a typo in thier code. Look at the
2 Response.BinaryWrite statements:
Response.BinaryWrite adoStream.Read(chunk)
Response.BinaryWrite objStream.Read(iSz Mod chunk)

Bret


"Ray Costanzo [MVP]" wrote:

> What's with the chunks? Perhaps try this code here.
>
> http://www.aspfaq.com/show.asp?id=2161
>
> Ray at work
>
> "Bret Thompson" <Bret (E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I am attempting to write an ASP page that will download a file rather then
> > open it, when it is of known type. I found this code here:
> > http://mosley.arach.net.au/dev/docs/save%20as.htm
> >
> > The first example works fine, for files under 5 Mb, the second example
> > downloads the file but the data is corrupted. Using a JGP file as a
> > reference, it seems to corrupt the end of the file (since the bottom of

> the
> > JPEG is corrupted).
> >
> > Here is the code I am using. Any idea how to fix this? or an alternative
> > method?
> >
> >
> > Response.ContentType = "application/x-unknown"
> > Response.AddHeader "content-disposition","attachment; filename=" &
> > Request.QueryString("File")
> >
> > Set adoStream = CreateObject("ADODB.Stream")
> > chunk = 2048
> > adoStream.Open()
> > adoStream.Type = 1
> > adoStream.LoadFromFile(Server.MapPath(vFilePath))
> >
> > iSz = adoStream.Size
> >
> > Response.AddHeader "Content-Length", iSz
> >
> > For i = 1 To iSz \ chunk
> > If Not Response.IsClientConnected Then Exit For
> > Response.BinaryWrite adoStream.Read(chunk)
> > Next
> >
> > If iSz Mod chunk > 0 Then
> > If Response.IsClientConnected Then
> > Response.BinaryWrite objStream.Read(iSz Mod chunk)
> > End If
> > End If
> >
> > adoStream.Close
> > Set adoStream = Nothing
> >
> > Response.End
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Email::MIME and Email::MIME::Attachment::Stripper ecureuil Perl Misc 0 05-28-2006 01:47 AM
Download dialog for known MIME type mizi ASP General 0 10-30-2005 10:38 AM
tomcat 4.x : setting mime type for a directory or setting a default mime type CJ Java 1 10-29-2004 07:51 PM
how 2 convert mime to txt or extract words from mime joe Perl Misc 0 04-07-2004 12:34 AM
Receiving zip files via Mime::Parser/Mime::Decoder Jan Arickx Perl Misc 0 08-25-2003 08:24 PM



Advertisments