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

File Download

Hey Guys
I have a web application that allows users to download files. But the files
are not hosted on the webserver. The files are stored on external servers and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.
Jan 13 '06 #1
6 2662

"Jatin" <Ja***@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #2
You are one the right track. You can string bytes to the client. If the
file is large, then just read and write chunks. You would want to use the
HttpWebRequest which exposes the source stream. i am not sure but I do not
think that it downloads the entire file. I would imagine that it is
buffered.

"Jatin" <Ja***@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #3
Hey peter
Need more help:

WebClient client = new WebClient();
Stream st = client.OpenRead(@"http://cre8object.biz.tm/testing/hello.avi");

Apparently this doesnt return me a stream. Also like i earlier said if i
used the client.downloadData methid it returns me a byte array. which is file
since i say stream it down response but the problem is that for large files
the Byte array could be large and in memory....

Can you reiterate on how i would use the httpwebrequest?

Thx and hope to hear from you


"Peter Rilling" wrote:
You are one the right track. You can string bytes to the client. If the
file is large, then just read and write chunks. You would want to use the
HttpWebRequest which exposes the source stream. i am not sure but I do not
think that it downloads the entire file. I would imagine that it is
buffered.

"Jatin" <Ja***@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.


Jan 13 '06 #4
One method you could use is to create as Web Service on the server hosting
the files. The a request can be made to your public server where an aspx
page will do any necessary processing to check there allowed to download the
requested file or not. The aspx page then set the response header
context-type to text/html, image/gif etc. or whatever you data file is.

Using SAOP you can then connect to your file server and request the file.
This will stream the file across in predefined chunks, which you write
direct to the response buffer and flush the results. You then request the
next chunk through the web service interface until the entire file has been
transferred. The method of requesting the next buffer can be accomplished in
several ways but by far the simplest is to use the current offset. For
example offset of 0 will send the first chunk of the file and you increment
the position by the size of the buffer until the entire file has been
received. This will allow the client side (web server) to specify the size
of the buffer as well so you can control the speed at which the user
receives the file. i.e. The higher the user status the faster you will try
and stream the file to them.

- Mike

---------------------------------------------------------------------------------
http://www.cogitar.net"> Cogitar Software. ( http://www.cogitar.net )
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://www.shop-dominion.com (senery landscape picture gallery)
---------------------------------------------------------------------------------
"Jatin" <Ja***@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #5
Hi Mike
Yea sounds like a good idea. I didnt think of the solution in that
perspective. I think i will keep this solution handy if all fails. I am
reluctant well the client might be reluctant to put up a webservice. so im
going to hold on to this.

Ideally i would really like to just stream it directly. If you see my reply
to the 'Peter' you will see i am trying to get it working with the webclient,
or any other alternative

Thanks a bunch Mike

"Mike" wrote:
One method you could use is to create as Web Service on the server hosting
the files. The a request can be made to your public server where an aspx
page will do any necessary processing to check there allowed to download the
requested file or not. The aspx page then set the response header
context-type to text/html, image/gif etc. or whatever you data file is.

Using SAOP you can then connect to your file server and request the file.
This will stream the file across in predefined chunks, which you write
direct to the response buffer and flush the results. You then request the
next chunk through the web service interface until the entire file has been
transferred. The method of requesting the next buffer can be accomplished in
several ways but by far the simplest is to use the current offset. For
example offset of 0 will send the first chunk of the file and you increment
the position by the size of the buffer until the entire file has been
received. This will allow the client side (web server) to specify the size
of the buffer as well so you can control the speed at which the user
receives the file. i.e. The higher the user status the faster you will try
and stream the file to them.

- Mike

---------------------------------------------------------------------------------
http://www.cogitar.net"> Cogitar Software. ( http://www.cogitar.net )
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://www.shop-dominion.com (senery landscape picture gallery)
---------------------------------------------------------------------------------
"Jatin" <Ja***@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
Hey Guys
I have a web application that allows users to download files. But the
files
are not hosted on the webserver. The files are stored on external servers
and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download
method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i
then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.


Jan 13 '06 #6
Hey guys
Thx guys. I got the download thing working. Here is the code im using for
anyone else with the same problem:
Stream st = null;

WebClient client;

try

{
client = new WebClient();
string filePath = @"http://XYZ/temp/files/COUNT24.AVI";
st = client.OpenRead(filePath);
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=" + filename);
int length;
bool completed = true;
byte[] buffer = new Byte[10000];

while (st.CanRead && completed == true)
{
length = st.Read(buffer, 0, 10000);
Response.OutputStream.Write(buffer, 0, length);
Response.Flush();
buffer = new Byte[10000];
if(length==0)
{
completed = false;
}
}
}
catch
{
//Response.Write("Error : " + ex.Message);
}
finally
{
if (st != null)
{
st.Close();
}
}
"Jatin" wrote:
Hey Guys
I have a web application that allows users to download files. But the files
are not hosted on the webserver. The files are stored on external servers and
are referenced by a URL/URI. Since my application restricts the number of
downloads for the file per user, i cannot show the user the URL/URI of the
server hosting the file.
Therefore i need to some how route the file via my webserver, and then use
the Response to stream the stream to the client.

I have tried to work with the Webclient class, but the only download method
i could use is readopen(others download the file directly to local drive),
which works BUT since it downloads the whole file into a Byte[] which i then
use the response to stream to the client is not the best of ways since the
Byte[] is in memory and the files being downloaded can be large.

Please Help., someway i can use some sort of unbuffered stream to do the
trick.

Jan 13 '06 #7

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

Similar topics

5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
1
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
4
by: Nathan Sokalski | last post by:
I want to give visitors to my site the option of downloading a generated ..txt file by clicking a button. I know how to generate text files, but how do I cause the browser to pop up one of those...
3
by: tshad | last post by:
I have a function that downloads a file to the users computer and it works fine. The problem is that I then want the program to rename the file (file.move) to the same name plus todays date. ...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
4
by: Roberto Mora | last post by:
I have not done programming in a very long time and what is worst, I never learned VB. Although my job does not require this knowledge, I cam across a problem that although it seemed simple it has...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.