chopping file while sending it via asp response.binary write

N

.nLL

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.
 
A

Anthony Jones

.nLL said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top