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

Redirecting a big file with Response.BinaryWrite

Hi,

I really need you help because I'm not very familliar with ASP and I
could not find any solution to my problem.

To put you in situation, I have a CGI to which I send a file name, and
that script return me that file. But for security reason, I don't want
to publish the address of this CGI, so I encapsulated it in an ASP
file. This way, only this ASP file knows where the CGI is.

Here is my code :
<%
Server.ScriptTimeout = 1000 * 1000
url = "http://address.to.cgi?search_file=" & request("search_file")

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
ResolveTimeout = 5 * 1000
ConnectTimeout = 5 * 1000
SendTimeout = 60 * 1000
ReceiveTimeout = 60 * 1000
xmlhttp.setTimeouts ResolveTimeout, ConnectTimeout, SendTimeout,
ReceiveTimeout

xmlhttp.open "GET", url, false
xmlhttp.send ""
respContentType = xmlhttp.getResponseHeader("content-type")
Response.ContentType = xmlhttp.getResponseHeader("content-type")
Response.AddHeader "Content-Disposition",
xmlhttp.getResponseHeader("content-disposition")

Response.binaryWrite xmlhttp.responseBody

set xmlhttp = nothing
%>

The problem is that each time I try to copy a file bigger than 20Mb, I
get a "The page cannot be displayed". My script is failing at the
"Response.binaryWrite" because if I replace it by ' Response.write
"Hello World" ' , it works.

I try to break down the xmlhttp.responseBody and send it in many chunk
but I don't know how to do that :(

Any suggestion?

Thanks in advance

Dec 7 '06 #1
5 11990

"twiggy182" <tw*******@hotmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
Hi,

I really need you help because I'm not very familliar with ASP and I
could not find any solution to my problem.

To put you in situation, I have a CGI to which I send a file name, and
that script return me that file. But for security reason, I don't want
to publish the address of this CGI, so I encapsulated it in an ASP
file. This way, only this ASP file knows where the CGI is.

Here is my code :
<%
Server.ScriptTimeout = 1000 * 1000
url = "http://address.to.cgi?search_file=" & request("search_file")

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
ResolveTimeout = 5 * 1000
ConnectTimeout = 5 * 1000
SendTimeout = 60 * 1000
ReceiveTimeout = 60 * 1000
xmlhttp.setTimeouts ResolveTimeout, ConnectTimeout, SendTimeout,
ReceiveTimeout

xmlhttp.open "GET", url, false
xmlhttp.send ""
respContentType = xmlhttp.getResponseHeader("content-type")
Response.ContentType = xmlhttp.getResponseHeader("content-type")
Response.AddHeader "Content-Disposition",
xmlhttp.getResponseHeader("content-disposition")

Response.binaryWrite xmlhttp.responseBody

set xmlhttp = nothing
%>

The problem is that each time I try to copy a file bigger than 20Mb, I
get a "The page cannot be displayed". My script is failing at the
"Response.binaryWrite" because if I replace it by ' Response.write
"Hello World" ' , it works.

I try to break down the xmlhttp.responseBody and send it in many chunk
but I don't know how to do that :(

Any suggestion?

You may be hitting the buffer limit on the server. How big a resource are
you expecting to send? Is it possible to increase the buffer limit? Try
Response.Write UBound(xmlhttp.responseBody) this will confirm that the CGI
get has been successful and the actual size of the resource being fetched.

If it's not possible to increase the buffer limit then one alternative might
be to use and ADODB.Stream object:-

'Warning: air code.

Const clChunkSize = 1048576 ' 1MB
Response.Buffer = False

' Set response headers here

Dim oStream : Set oStream = Server.CreateObject("ADODB.Stream")

oStream.Type = 1 ' Binary
oStream.open
oStream.write xmlhttp.responseBody
Set xmlhttp = Nothing ' Hopefully this will release some significant memory
oStream.position = 0

Dim i
For i = 0 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
oStream.close

Thanks in advance

Dec 7 '06 #2
Hi Anthony,

thank you so much! Your air code is working like a charm!

Actually, I tried almost the same code yesterday but I was getting a
"Type Mismatch" exception when I was calling the "Response.BinaryWrite"
function. Could be because I was calling "Response.flush" in the
loop...

Anyway, thanks again. And for your information ( and maybe for other
persons facing this problem ), I was trying to copy files of 40Mb. I
first had to increase the "AspBufferingLimit" to something around 50Mb
(In IIS). This fixed the buffer exception I was getting. At that point,
I was able to download files smaller than 20Mb only ( go figure why 20
). This new code seems to work around this limit.

Another interesting point, I was facing this problem on IIS 6 running
on Win2000 server. But on my desktop with IIS 5, it was working
alright, even if an external PC connect to my desktop.

OK, Merry Christmas ;)

Bye

Anthony Jones a écrit :
"twiggy182" <tw*******@hotmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
Hi,

I really need you help because I'm not very familliar with ASP and I
could not find any solution to my problem.

To put you in situation, I have a CGI to which I send a file name, and
that script return me that file. But for security reason, I don't want
to publish the address of this CGI, so I encapsulated it in an ASP
file. This way, only this ASP file knows where the CGI is.

Here is my code :
<%
Server.ScriptTimeout = 1000 * 1000
url = "http://address.to.cgi?search_file=" & request("search_file")

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
ResolveTimeout = 5 * 1000
ConnectTimeout = 5 * 1000
SendTimeout = 60 * 1000
ReceiveTimeout = 60 * 1000
xmlhttp.setTimeouts ResolveTimeout, ConnectTimeout, SendTimeout,
ReceiveTimeout

xmlhttp.open "GET", url, false
xmlhttp.send ""
respContentType = xmlhttp.getResponseHeader("content-type")
Response.ContentType = xmlhttp.getResponseHeader("content-type")
Response.AddHeader "Content-Disposition",
xmlhttp.getResponseHeader("content-disposition")

Response.binaryWrite xmlhttp.responseBody

set xmlhttp = nothing
%>

The problem is that each time I try to copy a file bigger than 20Mb, I
get a "The page cannot be displayed". My script is failing at the
"Response.binaryWrite" because if I replace it by ' Response.write
"Hello World" ' , it works.

I try to break down the xmlhttp.responseBody and send it in many chunk
but I don't know how to do that :(

Any suggestion?


You may be hitting the buffer limit on the server. How big a resource are
you expecting to send? Is it possible to increase the buffer limit? Try
Response.Write UBound(xmlhttp.responseBody) this will confirm that the CGI
get has been successful and the actual size of the resource being fetched.

If it's not possible to increase the buffer limit then one alternative might
be to use and ADODB.Stream object:-

'Warning: air code.

Const clChunkSize = 1048576 ' 1MB
Response.Buffer = False

' Set response headers here

Dim oStream : Set oStream = Server.CreateObject("ADODB.Stream")

oStream.Type = 1 ' Binary
oStream.open
oStream.write xmlhttp.responseBody
Set xmlhttp = Nothing ' Hopefully this will release some significant memory
oStream.position = 0

Dim i
For i = 0 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
oStream.close

Thanks in advance
Dec 7 '06 #3
Hi,

I'm now checking if it would be possible to enhance my code because
right now, it takes double the time to download a file ( copy from CGI
to ASP + copy from ASP to User ).

So is it possible to have a stream from the xmlhttp object? Basically,
I want a loop that extract 1Mb from "xmlhttp", and then push it to the
"Response".

Is it possible?
Thanks :)

Anthony Jones wrote:
"twiggy182" <tw*******@hotmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
Hi,

I really need you help because I'm not very familliar with ASP and I
could not find any solution to my problem.

To put you in situation, I have a CGI to which I send a file name, and
that script return me that file. But for security reason, I don't want
to publish the address of this CGI, so I encapsulated it in an ASP
file. This way, only this ASP file knows where the CGI is.

Here is my code :
<%
Server.ScriptTimeout = 1000 * 1000
url = "http://address.to.cgi?search_file=" & request("search_file")

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
ResolveTimeout = 5 * 1000
ConnectTimeout = 5 * 1000
SendTimeout = 60 * 1000
ReceiveTimeout = 60 * 1000
xmlhttp.setTimeouts ResolveTimeout, ConnectTimeout, SendTimeout,
ReceiveTimeout

xmlhttp.open "GET", url, false
xmlhttp.send ""
respContentType = xmlhttp.getResponseHeader("content-type")
Response.ContentType = xmlhttp.getResponseHeader("content-type")
Response.AddHeader "Content-Disposition",
xmlhttp.getResponseHeader("content-disposition")

Response.binaryWrite xmlhttp.responseBody

set xmlhttp = nothing
%>

The problem is that each time I try to copy a file bigger than 20Mb, I
get a "The page cannot be displayed". My script is failing at the
"Response.binaryWrite" because if I replace it by ' Response.write
"Hello World" ' , it works.

I try to break down the xmlhttp.responseBody and send it in many chunk
but I don't know how to do that :(

Any suggestion?


You may be hitting the buffer limit on the server. How big a resource are
you expecting to send? Is it possible to increase the buffer limit? Try
Response.Write UBound(xmlhttp.responseBody) this will confirm that the CGI
get has been successful and the actual size of the resource being fetched.

If it's not possible to increase the buffer limit then one alternative might
be to use and ADODB.Stream object:-

'Warning: air code.

Const clChunkSize = 1048576 ' 1MB
Response.Buffer = False

' Set response headers here

Dim oStream : Set oStream = Server.CreateObject("ADODB.Stream")

oStream.Type = 1 ' Binary
oStream.open
oStream.write xmlhttp.responseBody
Set xmlhttp = Nothing ' Hopefully this will release some significant memory
oStream.position = 0

Dim i
For i = 0 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
oStream.close

Thanks in advance
Dec 7 '06 #4

"twiggy182" <tw*******@hotmail.comwrote in message
news:11********************@j44g2000cwa.googlegrou ps.com...
Hi,

I'm now checking if it would be possible to enhance my code because
right now, it takes double the time to download a file ( copy from CGI
to ASP + copy from ASP to User ).

So is it possible to have a stream from the xmlhttp object? Basically,
I want a loop that extract 1Mb from "xmlhttp", and then push it to the
"Response".

Is it possible?
No. Data isn't available from XMLHTTP until the entire response from the
remote server has been received. I've even tried using the underlying
WinHTTP component which in async mode does deliver events as data is
received, however on trying to forward that to the client I found that
chunks of data we're being lost. I suspect that this may be due to WinHTTP
not being re-entrant, IOW using it in this way asychronously is fine so long
as you don't make other WinHTTP calls during the data received events.

The only other option that might be available if the remote resource would
accept byte range headers. You could then use xmlhttp in a loop pulling
chunks of the resource at a time. It's pretty hairy stuff and is highly
unlikely to work on a resource supplied by CGI.

Is't possible to mitigate the problem by caching the response on your
server?

Thanks :)

Anthony Jones wrote:
"twiggy182" <tw*******@hotmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
Hi,
>
I really need you help because I'm not very familliar with ASP and I
could not find any solution to my problem.
>
To put you in situation, I have a CGI to which I send a file name, and
that script return me that file. But for security reason, I don't want
to publish the address of this CGI, so I encapsulated it in an ASP
file. This way, only this ASP file knows where the CGI is.
>
Here is my code :
<%
Server.ScriptTimeout = 1000 * 1000
url = "http://address.to.cgi?search_file=" & request("search_file")
>
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
ResolveTimeout = 5 * 1000
ConnectTimeout = 5 * 1000
SendTimeout = 60 * 1000
ReceiveTimeout = 60 * 1000
xmlhttp.setTimeouts ResolveTimeout, ConnectTimeout, SendTimeout,
ReceiveTimeout
>
xmlhttp.open "GET", url, false
xmlhttp.send ""
respContentType = xmlhttp.getResponseHeader("content-type")
Response.ContentType = xmlhttp.getResponseHeader("content-type")
Response.AddHeader "Content-Disposition",
xmlhttp.getResponseHeader("content-disposition")
>
Response.binaryWrite xmlhttp.responseBody
>
set xmlhttp = nothing
%>
>
The problem is that each time I try to copy a file bigger than 20Mb, I
get a "The page cannot be displayed". My script is failing at the
"Response.binaryWrite" because if I replace it by ' Response.write
"Hello World" ' , it works.
>
I try to break down the xmlhttp.responseBody and send it in many chunk
but I don't know how to do that :(
>
Any suggestion?
>

You may be hitting the buffer limit on the server. How big a resource
are
you expecting to send? Is it possible to increase the buffer limit? Try
Response.Write UBound(xmlhttp.responseBody) this will confirm that the
CGI
get has been successful and the actual size of the resource being
fetched.

If it's not possible to increase the buffer limit then one alternative
might
be to use and ADODB.Stream object:-

'Warning: air code.

Const clChunkSize = 1048576 ' 1MB
Response.Buffer = False

' Set response headers here

Dim oStream : Set oStream = Server.CreateObject("ADODB.Stream")

oStream.Type = 1 ' Binary
oStream.open
oStream.write xmlhttp.responseBody
Set xmlhttp = Nothing ' Hopefully this will release some significant
memory
oStream.position = 0

Dim i
For i = 0 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
oStream.close

Thanks in advance
>

Dec 8 '06 #5
Hi,

thanks for the information. We will have to live with average
performances...

As for caching stuff on the server, it would work because there are too
many different request, and performance gain would be on rare requests.

Thanks again!

Anthony Jones wrote:
"twiggy182" <tw*******@hotmail.comwrote in message
news:11********************@j44g2000cwa.googlegrou ps.com...
Hi,

I'm now checking if it would be possible to enhance my code because
right now, it takes double the time to download a file ( copy from CGI
to ASP + copy from ASP to User ).

So is it possible to have a stream from the xmlhttp object? Basically,
I want a loop that extract 1Mb from "xmlhttp", and then push it to the
"Response".

Is it possible?

No. Data isn't available from XMLHTTP until the entire response from the
remote server has been received. I've even tried using the underlying
WinHTTP component which in async mode does deliver events as data is
received, however on trying to forward that to the client I found that
chunks of data we're being lost. I suspect that this may be due to WinHTTP
not being re-entrant, IOW using it in this way asychronously is fine so long
as you don't make other WinHTTP calls during the data received events.

The only other option that might be available if the remote resource would
accept byte range headers. You could then use xmlhttp in a loop pulling
chunks of the resource at a time. It's pretty hairy stuff and is highly
unlikely to work on a resource supplied by CGI.

Is't possible to mitigate the problem by caching the response on your
server?

Thanks :)

Anthony Jones wrote:
"twiggy182" <tw*******@hotmail.comwrote in message
news:11*********************@80g2000cwy.googlegrou ps.com...
Hi,

I really need you help because I'm not very familliar with ASP and I
could not find any solution to my problem.

To put you in situation, I have a CGI to which I send a file name, and
that script return me that file. But for security reason, I don't want
to publish the address of this CGI, so I encapsulated it in an ASP
file. This way, only this ASP file knows where the CGI is.

Here is my code :
<%
Server.ScriptTimeout = 1000 * 1000
url = "http://address.to.cgi?search_file=" & request("search_file")

set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
ResolveTimeout = 5 * 1000
ConnectTimeout = 5 * 1000
SendTimeout = 60 * 1000
ReceiveTimeout = 60 * 1000
xmlhttp.setTimeouts ResolveTimeout, ConnectTimeout, SendTimeout,
ReceiveTimeout

xmlhttp.open "GET", url, false
xmlhttp.send ""
respContentType = xmlhttp.getResponseHeader("content-type")
Response.ContentType = xmlhttp.getResponseHeader("content-type")
Response.AddHeader "Content-Disposition",
xmlhttp.getResponseHeader("content-disposition")

Response.binaryWrite xmlhttp.responseBody

set xmlhttp = nothing
%>

The problem is that each time I try to copy a file bigger than 20Mb, I
get a "The page cannot be displayed". My script is failing at the
"Response.binaryWrite" because if I replace it by ' Response.write
"Hello World" ' , it works.

I try to break down the xmlhttp.responseBody and send it in many chunk
but I don't know how to do that :(

Any suggestion?

>
>
You may be hitting the buffer limit on the server. How big a resource
are
you expecting to send? Is it possible to increase the buffer limit? Try
Response.Write UBound(xmlhttp.responseBody) this will confirm that the
CGI
get has been successful and the actual size of the resource being
fetched.
>
If it's not possible to increase the buffer limit then one alternative
might
be to use and ADODB.Stream object:-
>
'Warning: air code.
>
Const clChunkSize = 1048576 ' 1MB
Response.Buffer = False
>
' Set response headers here
>
Dim oStream : Set oStream = Server.CreateObject("ADODB.Stream")
>
oStream.Type = 1 ' Binary
oStream.open
oStream.write xmlhttp.responseBody
Set xmlhttp = Nothing ' Hopefully this will release some significant
memory
oStream.position = 0
>
Dim i
For i = 0 To oStream.Size \ clChunkSize
Response.BinaryWrite oStream.Read(clChunkSize)
Next
oStream.close
>
>
>
>
Thanks in advance
Jan 5 '07 #6

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

Similar topics

6
by: Don Grover | last post by:
How can I force a download of a csv file by user clicking on hyperlink. Don
3
by: Derrick | last post by:
I have an http download that streams a zip file to client, after download I am getting "Error start of central directory not found; Zip file corrupt. Possible casue: file transfer error." Ring...
0
by: PeterB | last post by:
Hi! I am using the script below to download files, that are in a non-public directory, from my site. The "smaller files" section works for smaller files. However when the files are getting...
2
by: Zam | last post by:
Hello World, Under Windows 2003 Server. IIS6. The following code working fine for small files, and for files with size about few megabytes. If I am trying to send HUGE file -- about 700...
2
by: hoenes1 | last post by:
I've got an aspx-Page "SendFile.aspx" which is called by a Link on "ShowListOfFiles.aspx" and sends the file in the OnLoad Eventhandler. The filename to download is stored in a Session variable....
13
by: Prabhat | last post by:
Hi Friends, I have code that will "BinaryWrite" a EXE file of 20mb to client using the ADO Stream. After the download the EXE file works fine without any problem. When I verified the EXE that...
5
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, The following code was suggested by one of the users in this newsgroup when a pdf file was requested by a user from an asp page. I used the similar code in my page and the very interesting...
17
by: mansb2002 | last post by:
Hi, We recently moved our webserver from Win2K to Win2003. The application works fine. Only problem is that when user views a report as a PDF, IE does not show it. The following code is used to...
14
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
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
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...

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.