|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File DownloadHey 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.
Show quote
Hide quote
"Jatin" <Ja***@discussions.microsoft.com> wrote in message
news:D6DFAEF9-22C8-42C4-AE98-CEC480C3E38A@microsoft.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. 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. Show quoteHide quote "Jatin" <Ja***@discussions.microsoft.com> wrote in message news:D6DFAEF9-22C8-42C4-AE98-CEC480C3E38A@microsoft.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. 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 Show quoteHide quote "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:D6DFAEF9-22C8-42C4-AE98-CEC480C3E38A@microsoft.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. > > > 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) --------------------------------------------------------------------------------- Show quoteHide quote "Jatin" <Ja***@discussions.microsoft.com> wrote in message news:D6DFAEF9-22C8-42C4-AE98-CEC480C3E38A@microsoft.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. 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 Show quoteHide quote "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:D6DFAEF9-22C8-42C4-AE98-CEC480C3E38A@microsoft.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. > > > 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(); } } Show quoteHide quote "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.
Other interesting topics
Seeking examples of screen scraping....
Issue with ASP.NET 2.0 Global asax Help: ASP.Net broken (tried usual suspects...) Can't open asp xml page Question about string Error: 'CreateUser' is not a member of 'Membership' vs2005: domain trust relationship problem FormsAuthentication.SignOut() and User.Identity Website config tool asp.net 2.0 XMLHTTP question |
|||||||||||||||||||||||