0

need some help in downloading file with ashx

i'm trying to download large file (about 2-4GB) from external link (file not stored on webserver)

here is my code

context.Response.Clear();
context.Response.ContentType = "video/mp4";
context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
context.Response.Write("http://otherserver/file.m4v");
context.Response.Flush();
context.Response.Close();

and downloaded file is 1kb what i;m doing wrong? and is other way to download file? I'm trying to force browser to download file (and change filename) not to preview in brower

P.S sory for my english ;)

Jaztingo
  • 570
  • 1
  • 5
  • 15

2 Answers2

1

This is an incorrect approach. The file content will be:

http://otherserver/file.m4v

Which you are setting here:

context.Response.Write("http://otherserver/file.m4v");

What you need to use is the HttpWebRequest Class.

Alex Filipovici
  • 31,789
  • 6
  • 54
  • 78
0

All you're doing is sending the browser a file containing the text "http://otherserver/file.m4v", with a header suggesting that the browser offers to download, rather than display, the file.

There's no magic going on in the browser that causes it to say "Oh, I should download whatever's at that URL" when it sees a file with a URL in it.

Moreover, having Googled around a bit and looked at several PHP discussions on this subject, I don't think there's a way to do what you want without literally streaming the file from the remote URL onto your server, and then sending it on from your server to the client.

You could try adding the header and then sending a redirect to the client, but I'd expect the client to discard the header when it makes the request to the remote URL - and so display the result in the browser.

Community
  • 1
  • 1
Rawling
  • 49,248
  • 7
  • 89
  • 127