473,383 Members | 1,868 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,383 software developers and data experts.

file size limit in Response.binarywrite

S N
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client.
Kindly indicate the maximum size of the file that can be downloaded using this method.
I am hosting this site on a public server, so I will not be able to change anything on the webserver. Kindly indicate what can be done to ensure that the above method remains valid for any file size download.

call Response.AddHeader("Content-Disposition","attachment; filename=""" & strFileSave & """")
Response.ContentType = "bad/type"
Set Fsys = Server.CreateObject("Scripting.FileSystemObject")
Set TS = Fsys.GetFile(strFile).OpenAsTextStream(1, -1)
Do While Not (TS.AtEndOfStream)
Response.BinaryWrite(TS.Read(1))
Loop
Sep 7 '08 #1
14 11847
"S N" wrote:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client.
Kindly indicate the maximum size of the file that can be downloaded using this method.
call Response.AddHeader("Content-Disposition","attachment; filename=""" & strFileSave & """")
Response.ContentType = "bad/type"
Set Fsys = Server.CreateObject("Scripting.FileSystemObject")
Set TS = Fsys.GetFile(strFile).OpenAsTextStream(1, -1)
Do While Not (TS.AtEndOfStream)
Response.BinaryWrite(TS.Read(1))
Loop
Ummm...that code isn't goint to work, anyway. See the method
OpenAsTEXTstream
???

You really can only use FileSystemObject reliably with text files; it wasn't
designed to work with binary files.

You need to use ADODB.Stream object, instead.
http://msdn.microsoft.com/en-us/libr...32(VS.85).aspx

And then you could easily control the amount you write in each chunk by just
limiting the amount you Read each time.
Sep 8 '08 #2
S N
Thanks for the advice. I was under the impression that ADODB can be used
only for databases. This is the first instance of using it on files.
Can you please provide a sample code to hide download url by using ADODB
stream, while there should be no limit on the size of files to be
downloaded.

..
"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:C3**********************************@microsof t.com...
"S N" wrote:
>I am using the following code to hide the download url of files on my
website. The code uses Response.Binarywrite to send file to the client.
Kindly indicate the maximum size of the file that can be downloaded using
this method.
call Response.AddHeader("Content-Disposition","attachment; filename=""" &
strFileSave & """")
Response.ContentType = "bad/type"
Set Fsys = Server.CreateObject("Scripting.FileSystemObject")
Set TS = Fsys.GetFile(strFile).OpenAsTextStream(1, -1)
Do While Not (TS.AtEndOfStream)
Response.BinaryWrite(TS.Read(1))
Loop

Ummm...that code isn't goint to work, anyway. See the method
OpenAsTEXTstream
???

You really can only use FileSystemObject reliably with text files; it
wasn't
designed to work with binary files.

You need to use ADODB.Stream object, instead.
http://msdn.microsoft.com/en-us/libr...32(VS.85).aspx

And then you could easily control the amount you write in each chunk by
just
limiting the amount you Read each time.

Sep 8 '08 #3


"S N" wrote:
Can you please provide a sample code to hide download url by using ADODB
stream, while there should be no limit on the size of files to be
downloaded.
Good old Atrax has a couple of demos.

Note that his code is written in JScript for ASP, but conversion to VBScript
should be easy.

http://rtfm.atrax.co.uk/infinitemonk...es/asp/934.asp
and
http://rtfm.atrax.co.uk/infinitemonk...es/asp/935.asp

If you need more help, ask.
Sep 8 '08 #4
S N
I would be grateful if you can give me vbscript code as well.
I would also like to clarify that the code for jscript forces save as
dialog. What if we want to hide the download url but dont want to force the
save as dialog, instead just want to see the pdf file within the browser
window itself.
Kindly advise on this.

Thanks in anticipation.

"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:03**********************************@microsof t.com...
>

"S N" wrote:
>Can you please provide a sample code to hide download url by using ADODB
stream, while there should be no limit on the size of files to be
downloaded.

Good old Atrax has a couple of demos.

Note that his code is written in JScript for ASP, but conversion to
VBScript
should be easy.

http://rtfm.atrax.co.uk/infinitemonk...es/asp/934.asp
and
http://rtfm.atrax.co.uk/infinitemonk...es/asp/935.asp

If you need more help, ask.

Sep 9 '08 #5

"S N" <ua******@yahoo.comwrote in message
news:un**************@TK2MSFTNGP05.phx.gbl...
>I am using the following code to hide the download url of files on my
website. The code uses Response.Binarywrite to send file to the >client.
Kindly indicate the maximum size of the file that can be downloaded using
this method.
I am hosting this site on a public server, so I will not be able to change
anything on the webserver. Kindly indicate what can be done to >ensure that
the above method remains valid for any file size download.

call Response.AddHeader("Content-Disposition","attachment; filename=""" &
strFileSave & """")
Response.ContentType = "bad/type"
Set Fsys = Server.CreateObject("Scripting.FileSystemObject")
Set TS = Fsys.GetFile(strFile).OpenAsTextStream(1, -1)
Do While Not (TS.AtEndOfStream)
Response.BinaryWrite(TS.Read(1))
Loop
Use this code:-

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

SendFileToResponse strFile, strFileSave

Note the Response.Buffer = false allows you to send a file of any size.

--
Anthony Jones - MVP ASP/ASP.NET

Sep 9 '08 #6
S N
What if we want to use sendfiletoresponse but dont want to force the save as
dialog, instead just want to see the pdf file within the browser window
itself.
is there any change required in the code to achieve this.

"Anthony Jones" <An***********@yadayadayada.comwrote in message
news:e5**************@TK2MSFTNGP06.phx.gbl...
>
"S N" <ua******@yahoo.comwrote in message
news:un**************@TK2MSFTNGP05.phx.gbl...
>>I am using the following code to hide the download url of files on my
website. The code uses Response.Binarywrite to send file to the >client.
Kindly indicate the maximum size of the file that can be downloaded using
this method.
I am hosting this site on a public server, so I will not be able to change
anything on the webserver. Kindly indicate what can be done to >ensure
that the above method remains valid for any file size download.

call Response.AddHeader("Content-Disposition","attachment; filename=""" &
strFileSave & """")
Response.ContentType = "bad/type"
Set Fsys = Server.CreateObject("Scripting.FileSystemObject")
Set TS = Fsys.GetFile(strFile).OpenAsTextStream(1, -1)
Do While Not (TS.AtEndOfStream)
Response.BinaryWrite(TS.Read(1))
Loop

Use this code:-

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

SendFileToResponse strFile, strFileSave

Note the Response.Buffer = false allows you to send a file of any size.

--
Anthony Jones - MVP ASP/ASP.NET


Sep 9 '08 #7
"S N" <ua******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
What if we want to use sendfiletoresponse but dont want to force the save
as dialog, instead just want to see the pdf file within the browser window
itself.
is there any change required in the code to achieve this.
If you know its a pdf then change content-type to application/pdf and remove
the attachment; keyword from content-disposition.

--
Anthony Jones - MVP ASP/ASP.NET

Sep 9 '08 #8
S N
Following error received:

Response object error 'ASP 0157 : 80004005'
Buffering On

/test/dl.asp, line 2

Buffering cannot be turned off once it is already turned on.
Please note that I am hosting the site on a public server so there is no way
to ask the web admin to configure the server specifically for me. In such a
situation is it possible to eliminate the error as indicated above. Further,
if I am not able to switch off the response.buffer, will there be any
limitation on the size of file that i can download using
response.binarywrite?


"Anthony Jones" <An***********@yadayadayada.comwrote in message
news:e9**************@TK2MSFTNGP02.phx.gbl...
"S N" <ua******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>What if we want to use sendfiletoresponse but dont want to force the save
as dialog, instead just want to see the pdf file within the browser
window itself.
is there any change required in the code to achieve this.

If you know its a pdf then change content-type to application/pdf and
remove the attachment; keyword from content-disposition.

--
Anthony Jones - MVP ASP/ASP.NET


Sep 9 '08 #9
"S N" <ua******@yahoo.comwrote in message
news:u4**************@TK2MSFTNGP06.phx.gbl...
Following error received:

Response object error 'ASP 0157 : 80004005'
Buffering On

/test/dl.asp, line 2

Buffering cannot be turned off once it is already turned on.
You get this error if there is anything in your page or includes at the top
of the page which writes stuff to the response before your code has run.
Note any static content in the page will be sent.

Typical a page of this sort looks like:-

<!-- #include .... some common include -->
<%

' Code here that should note writing anything.
'My code I posted to you with your mods.
%>

Where the include is of a similar structure defininng constants and utility
functions.
>
Please note that I am hosting the site on a public server so there is no
way to ask the web admin to configure the server specifically for me.
Whilst an admin may have configured the buffer to be on (which is the
default) you can set it off as long as you do so before sending anything.
>In such a situation is it possible to eliminate the error as indicated
above. Further, if I am not able to switch off the response.buffer, will
there be any limitation on the size of file that i can download using
response.binarywrite?
Without turning it off there will be a limitation. The is a buffer size
limit that a public server administrator will almost certainly have
configured (the default on IIS6 is 4MB).

--
Anthony Jones - MVP ASP/ASP.NET

Sep 9 '08 #10
S N
Also advise the content type in case the file is an excel file, word
document, exe file, zip file etc.

Thanks in advance.
"Anthony Jones" <An***********@yadayadayada.comwrote in message
news:e9**************@TK2MSFTNGP02.phx.gbl...
"S N" <ua******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>What if we want to use sendfiletoresponse but dont want to force the save
as dialog, instead just want to see the pdf file within the browser
window itself.
is there any change required in the code to achieve this.

If you know its a pdf then change content-type to application/pdf and
remove the attachment; keyword from content-disposition.

--
Anthony Jones - MVP ASP/ASP.NET


Sep 9 '08 #11


"S N" wrote:
Just one clarification
You intended
For i = 1 To oStream.Size / clChunkSize
or
For i = 1 To oStream.Size \ clChunkSize
He *intended* the latter.

The backslash operator means "integer division" in VBScript (and VB and
VB.NET) code.

That is,
a \ b
is equivalent to
INT( a / b )

********************

Also, you don't need to mess with Response.Buffer=False, at all.

Just follow each
Response.BinaryWrite
with
Response.Flush

Now the buffer will never get more full than one "chunkSize".
Sep 10 '08 #12
"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
>

"S N" wrote:
>Just one clarification
You intended
For i = 1 To oStream.Size / clChunkSize
or
For i = 1 To oStream.Size \ clChunkSize

He *intended* the latter.

The backslash operator means "integer division" in VBScript (and VB and
VB.NET) code.

That is,
a \ b
is equivalent to
INT( a / b )

********************

Also, you don't need to mess with Response.Buffer=False, at all.

Just follow each
Response.BinaryWrite
with
Response.Flush

Now the buffer will never get more full than one "chunkSize".
Yes that would work. However it would mask unintended errors that turning
the buffer off right at the top of the code exposes.

--
Anthony Jones - MVP ASP/ASP.NET

Sep 10 '08 #13
S N

"Anthony Jones" <An***********@yadayadayada.comwrote in message
news:us**************@TK2MSFTNGP05.phx.gbl...
"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:85**********************************@microsof t.com...
>>

"S N" wrote:
>>Just one clarification
You intended
For i = 1 To oStream.Size / clChunkSize
or
For i = 1 To oStream.Size \ clChunkSize

He *intended* the latter.

The backslash operator means "integer division" in VBScript (and VB and
VB.NET) code.

That is,
a \ b
is equivalent to
INT( a / b )

********************

Also, you don't need to mess with Response.Buffer=False, at all.

Just follow each
Response.BinaryWrite
with
Response.Flush

Now the buffer will never get more full than one "chunkSize".

Yes that would work. However it would mask unintended errors that turning
the buffer off right at the top of the code exposes.

--
Anthony Jones - MVP ASP/ASP.NET



what kind of errors would be exposed by turning off the buffer. kindly
elaborate.
Sep 13 '08 #14
"S N" <ua******@yahoo.comwrote in message
news:OY*************@TK2MSFTNGP02.phx.gbl...
>
"Anthony Jones" <An***********@yadayadayada.comwrote in message
news:us**************@TK2MSFTNGP05.phx.gbl...
>"Old Pedant" <Ol*******@discussions.microsoft.comwrote in message
news:85**********************************@microso ft.com...
>>>

"S N" wrote:

Just one clarification
You intended
For i = 1 To oStream.Size / clChunkSize
or
For i = 1 To oStream.Size \ clChunkSize

He *intended* the latter.

The backslash operator means "integer division" in VBScript (and VB and
VB.NET) code.

That is,
a \ b
is equivalent to
INT( a / b )

********************

Also, you don't need to mess with Response.Buffer=False, at all.

Just follow each
Response.BinaryWrite
with
Response.Flush

Now the buffer will never get more full than one "chunkSize".

Yes that would work. However it would mask unintended errors that
turning the buffer off right at the top of the code exposes.


what kind of errors would be exposed by turning off the buffer. kindly
elaborate.
Well the sort of problems you've discovered where you may unintentionaly be
placing things in the output buffer that you didn't want present. Example:-

<!-- #include /virtual="/someinclude.asp" -->
<%
Response.ContentType = "application/octet-stream"
Do Until ....
Response.BinaryWrite SomeStuff
Response.Flush
Loop
%>

'someinclude.asp

<!-- Ooops some accidental static content here -->
<%

'utility code

%>

Placing a Response.Buffer at the top of your page would barf immediately on
that line alerting you to a problem.
It also saves you having to remember to Response.Flush if you have multiple
places where you write to the buffer.

--
Anthony Jones - MVP ASP/ASP.NET

Sep 13 '08 #15

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

Similar topics

2
by: Milan | last post by:
Hi! I am loading XML file this way: oDom = Server.CreateObject("Microsoft.XMLDOM") oDom.async = False If oDom.Load(Server.MapPath("lang/EN.xml")) Then GetXMLDocument = oDom.documentElement...
2
by: steve | last post by:
I am setting up a huge database in mysql, and I get the above error in Linux. I believe it is related to the size of one of my tables, which is 4,294,966,772 bytes in size. Can someone help. How...
8
by: Peter Ballard | last post by:
Hi all, I've got a C program which outputs all its data using a statement of the form: putchar(ch, outfile); This has worked fine for years until it had to output more than 2GB of data...
0
by: Ben | last post by:
I use the following method to export data to an excel file. Is there a size limit? It seems that the size is big (about 2, 3 MB), it hangs when attempt to open the file. Response.Clear() ;...
1
by: Amod | last post by:
Hi, I m copying data from a video stream on the hard disk using a C++ programme in win32 API. my current file system is FAT32 .. the file size limit of FAT32 is 4GB. I want to automatically split...
1
by: Amod | last post by:
Hi, I m copying data from a video stream on the hard disk using a C++ programme in win32 API. my current file system is FAT32 .. the file size limit of FAT32 is 4GB. I want to automatically split...
9
by: eastcoastguyz | last post by:
I wrote a simple program to continue to create a very large file (on purpose), and even though there is plenty of disk space on that device the program aborted with the error message "File Size...
1
by: MichiMichi | last post by:
I am trying to secure filedownload via streaming to protect files on the server. This works very well but when I open the file in a notepad editor it shows always HTML code at the end of the file....
0
by: S N | last post by:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client. Kindly indicate the maximum size of the file that can be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.