473,441 Members | 1,372 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

chopping file while sending it via asp response.binary write

hi everyone. i use asp to send files to users to prevent hotlinking and i
always used following code

Response.ContentType="video/3gpp"
response.addheader "Content-Disposition", "attachment;filename="& file
& ";"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile "c:\my.file"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing

none of the files bigger than 4 mb. but today i have read read following
(couple posts below)

Sub SendFileToResponse(FilePath, FileName)

Const clChunkSize = 1048576 ' 1MB

Dim oStream, i
Response.Buffer = False

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", _
"attachment; Filename=" & FileName

Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = 1 ' Binary
oStream.Open
oStream.LoadFromFile FilePath

For i = 1 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
If (oStream.Size Mod clChunkSize) <0 Then
Response.BinaryWrite oStream.Read(oStream.Size Mod
clChunkSize)
End If
oStream.Close

End Sub


so my question is which one is better and more efficient? in my case only
mobile phones used to download and i am not sure if copping files could
couse problem.
Feb 13 '07 #1
1 6269

".nLL" <no***@here.comwrote in message
news:IA*********************@fe1.news.blueyonder.c o.uk...
hi everyone. i use asp to send files to users to prevent hotlinking and i
always used following code

Response.ContentType="video/3gpp"
response.addheader "Content-Disposition", "attachment;filename="&
file
& ";"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile "c:\my.file"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing

none of the files bigger than 4 mb. but today i have read read following
(couple posts below)

Sub SendFileToResponse(FilePath, FileName)

Const clChunkSize = 1048576 ' 1MB

Dim oStream, i
Response.Buffer = False

Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", _
"attachment; Filename=" & FileName

Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Type = 1 ' Binary
oStream.Open
oStream.LoadFromFile FilePath

For i = 1 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
If (oStream.Size Mod clChunkSize) <0 Then
Response.BinaryWrite oStream.Read(oStream.Size Mod
clChunkSize)
End If
oStream.Close

End Sub


so my question is which one is better and more efficient? in my case only
mobile phones used to download and i am not sure if copping files could
couse problem.

The stick with your simpler solution. It's likely to be faster and is less
likely to go wrong. That is unless you do hit the buffer limit.

Feb 13 '07 #2

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

Similar topics

3
by: Ot?vio | last post by:
Hi! I'm havin a problem about sending a binary file with fsockopen. My problem is solved when i do: -------------------->8------CODE----------------------------- <form...
7
by: Fernando Chilvarguer | last post by:
I'm having problems with a simple binary write. The page is just supposed to write a JPEG back to the browser but the image does not display (the "X" image shows). Any help is appreciated. Here's...
1
by: sleepylight | last post by:
I'm running into a strange problem with ostreams's write function. Please see the code below: ofstream save((job->b->get_filename()).c_str(), ios::out | ios::binary); if (!save) { cout <<...
0
by: brian.fairchild | last post by:
I have a downloader page in my asp.net application that looks at a session variable to get the path to the file, checks it then downloads it using the Response object. When the "File Download"...
8
by: Mantorok | last post by:
Hi all I have the contents of a text file that I would like to output to the response stream, however IE thinks it is XML and comes up with and error, here is the code: Response.ContentType =...
0
by: remya1000 | last post by:
by using FTP i can send files to server using vb.net. if the file is big, then it will take some time to complete the sending process to server.or if we were sending 3-4 files to the server one by...
2
by: jayesch | last post by:
Hi All, I have a small program that is trying to POST and XML to an ASP.net aspx web page. I am using WebRequest and WebResponse classes for communication between aspx and client program....
7
by: chelle2100 | last post by:
hi... i need to write a converter to convert the text file to a binary file with the following file format... CharacterCount:Unsigned Char(This stores the number of characters that is in the file)...
4
by: AAaron123 | last post by:
trying to understand the below shown code. After this is run the browser opens a file-save dialog box for saving the file. I wonder how it knows I want the file saved? But more important, the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.