开发者

Streaming a file in ASP.NET, C#?

开发者 https://www.devze.com 2023-01-31 17:46 出处:网络
Assume we have the access to sth.avi on www.dl.com with a direct link. e.g : www.dl.com\\sth.avi Also we have a website => www.dl2.com.

Assume we have the access to sth.avi on www.dl.com with a direct link.

e.g : www.dl.com\sth.avi

Also we have a website => www.dl2.com.

Now, we wanna let some users to download sth.avi from www.dl2.com, but we don't have enough space on www.dl2.com to save sth.avi.

Is it possible in ASP.NET for us to read sth.avi from www.dl.com as streaming file and share it without saving the file on our domain.

P.S:

I don't wanna share this link www.dl.com\sth.avi, actually I wanna share something like this link www.dl2.com\downloads\sth.avi开发者_StackOverflow中文版


Instead of streaming simply configure the web server on www.dl2.com to redirect requests for /downloads/sth.avi to www.dl.com/sth.avi.


Yes.

Make an HttpWebRequest to dl.com/... and copy the HttpWebResponse to Response.Out.

Make sure to disable buffering.


Well.... this is feasible, but it looks to me as a bad idea.

In order to achieve your result, you must open an HTTP request to www.dl.com (the hoster of the video) and then, once you read bytes from there, redirect them to Response stream.

I can't provide you with working code, but here is pseudo code

using (Stream fileStream = [open HTTP request to www.dl.com])
{
    while (fileStream is not ended)
    {
        buffer = fileStream.Read();
        Response.Write(buffer);
    }
}

I repeat: that was pseudo-code!!!

0

精彩评论

暂无评论...
验证码 换一张
取 消