473,795 Members | 2,498 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Downloading files of known mime type

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.Conten tType = "applicatio n/x-unknown"
Response.AddHea der "content-disposition","a ttachment; filename=" &
Request.QuerySt ring("File")

Set adoStream = CreateObject("A DODB.Stream")
chunk = 2048
adoStream.Open( )
adoStream.Type = 1
adoStream.LoadF romFile(Server. MapPath(vFilePa th))

iSz = adoStream.Size

Response.AddHea der "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClie ntConnected Then Exit For
Response.Binary Write adoStream.Read( chunk)
Next

If iSz Mod chunk > 0 Then
If Response.IsClie ntConnected Then
Response.Binary Write objStream.Read( iSz Mod chunk)
End If
End If

adoStream.Close
Set adoStream = Nothing

Response.End

Jul 22 '05 #1
3 4518
What's with the chunks? Perhaps try this code here.

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

Ray at work

"Bret Thompson" <Bret Th******@discus sions.microsoft .com> wrote in message
news:17******** *************** ***********@mic rosoft.com...
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.Conten tType = "applicatio n/x-unknown"
Response.AddHea der "content-disposition","a ttachment; filename=" &
Request.QuerySt ring("File")

Set adoStream = CreateObject("A DODB.Stream")
chunk = 2048
adoStream.Open( )
adoStream.Type = 1
adoStream.LoadF romFile(Server. MapPath(vFilePa th))

iSz = adoStream.Size

Response.AddHea der "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClie ntConnected Then Exit For
Response.Binary Write adoStream.Read( chunk)
Next

If iSz Mod chunk > 0 Then
If Response.IsClie ntConnected Then
Response.Binary Write objStream.Read( iSz Mod chunk)
End If
End If

adoStream.Close
Set adoStream = Nothing

Response.End

Jul 22 '05 #2
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 Th******@discus sions.microsoft .com> wrote in message
news:17******** *************** ***********@mic rosoft.com...
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.Conten tType = "applicatio n/x-unknown"
Response.AddHea der "content-disposition","a ttachment; filename=" &
Request.QuerySt ring("File")

Set adoStream = CreateObject("A DODB.Stream")
chunk = 2048
adoStream.Open( )
adoStream.Type = 1
adoStream.LoadF romFile(Server. MapPath(vFilePa th))

iSz = adoStream.Size

Response.AddHea der "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClie ntConnected Then Exit For
Response.Binary Write adoStream.Read( chunk)
Next

If iSz Mod chunk > 0 Then
If Response.IsClie ntConnected Then
Response.Binary Write objStream.Read( iSz Mod chunk)
End If
End If

adoStream.Close
Set adoStream = Nothing

Response.End


Jul 22 '05 #3
Ray,

Nevermind, I finally found it. There is a typo in thier code. Look at the
2 Response.Binary Write statements:
Response.Binary Write adoStream.Read( chunk)
Response.Binary Write 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 Th******@discus sions.microsoft .com> wrote in message
news:17******** *************** ***********@mic rosoft.com...
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.Conten tType = "applicatio n/x-unknown"
Response.AddHea der "content-disposition","a ttachment; filename=" &
Request.QuerySt ring("File")

Set adoStream = CreateObject("A DODB.Stream")
chunk = 2048
adoStream.Open( )
adoStream.Type = 1
adoStream.LoadF romFile(Server. MapPath(vFilePa th))

iSz = adoStream.Size

Response.AddHea der "Content-Length", iSz

For i = 1 To iSz \ chunk
If Not Response.IsClie ntConnected Then Exit For
Response.Binary Write adoStream.Read( chunk)
Next

If iSz Mod chunk > 0 Then
If Response.IsClie ntConnected Then
Response.Binary Write objStream.Read( iSz Mod chunk)
End If
End If

adoStream.Close
Set adoStream = Nothing

Response.End


Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4930
by: yawnmoth | last post by:
i have a short php script that creates a gz compressed file, but... when i try to download it, internet explorer doesn't prompt me for a download location, and then save it at that download location... instead, it just opens it as it would any old text document... this is not what i want it to do... i want to be able to download it, not view it. any ideas on how to do this? here's the code: <?
6
4823
by: Steve | last post by:
hello all im looking to make a download script as i cannot use the .htaccess to control directory access to files as im using a php login system using mysql and sessions. i have been playing about with fopen and fpassthru but having a few problems making the file download. The files involved would mainly be but not limited to .pdfs, .docs and .zips
12
5457
by: Swede | last post by:
Hello, I am posting this rather lengthy description here in hope of getting at least some insight into a problem that is really hurting my business, since I have come to the conclusion that my problem is at least partly PHP-related. Some time now I have been having transfer problems, i.e. my customers downloads of large binary (ZIP) files are often corrupt.
11
8776
by: Mark J. McGinty | last post by:
Greets, One site I've written allows the user to install an IE extension menu (not malware at all) by downloading/merging a short .REG file. Worked like a peach on Win2K Server, now that I upgraded to Server 2003, it returns a 404 file not found error. I'm positive the file is there/spelled right. I changed it to .txt and it displays the text in the user's browser. So there's little question that this is some "security" addition, to...
1
4079
by: Erik Cruz | last post by:
Hi. My application has a page where users can click on some links to download documents. When testing the page I noticed an strange behaviour. One of the links points to a .pps file. When I click this link, the download window shows me the file name with a .ppt extension instead of the original .pps extension. I know both are Power Point files, but why IE changes the file extension? Is it a normal behaviour? TIA,
2
2776
by: Tomas Martinez | last post by:
Hi there! I'm trying to download a file in my asp.net web, but when downloading it from a Firefox browser, instead of downloading the example.exe file, it's downloading example.exe.htm. My code is the following: string localfile = MyComponent.DownloadMyExe(index); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType="application/octet-stream";
10
5511
by: mwt | last post by:
This code works fine to download files from the web and write them to the local drive: import urllib f = urllib.urlopen("http://www.python.org/blah/blah.zip") g = f.read() file = open("blah.zip", "wb") file.write(g) file.close()
8
1926
by: danish | last post by:
Hi, Can anyone suggest me why some .php files are downloading and some are executing. Ive got php 5.2.0 and apache 2.0.54. Apache came as an rpm along with Fedora 4. I downloaded php from the site and built it Thanks Danish
3
1415
by: bryanp10 | last post by:
I have a web application where the admin wants to be able to upload arbitrary files on an admin page... and then have them accessible for certain users. Easy enough eh? The difficulty I'm having is serving up these files in a secure AND browser-friendly way. I'm using Form authentication. I can't just drop them in a website directory and show links to the files, because then anyone could get at a file whose extension is not explicitly...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.