0

Here's what I would like to accomplish:

  • I have a file stored in Windows Azure Blob Storage (or for that matter any file which is not on my web server but accessible via a URL).
  • I want to force download a file without actually downloading the file on my web server first i.e. browser should automatically fetch the file from this external URL and prompts the user to download it.

Possible Solutions Explored:

Here's what I have explored so far (and why they won't work):

  • Using something like FileContentResult as described here Returning a file to View/Download in ASP.NET MVC to download the file. This solution would require me to fetch the contents on my server and then stream from my server to the browser. For this reason this solution won't work.
  • Using HTML 5 download attribute: HTML 5 download attribute would have worked perfectly fine however the problem is that while it is really a very neat solution, it is not supported in all browsers.
  • Changing the file's content type: Another thing I could do (at least for the files that I own) to change the content type property of the file to something that the browser wouldn't understand and thus would be forced to download the file. This might work in some browsers however not in all as IE is smart enough to go beyond the content type and sees the file's content to determine the content type. Furthermore if I don't own the files, then I won't have access to changing the content type of the file.

Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file.

Is this something which can be accomplished? If yes, then any ideas how I could accomplish this?

Community
  • 1
  • 1
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Why do you not just put the URL of the file in a link on the page - browser will just attempt to download it? – Paddy Nov 05 '13 at 09:39
  • Thanks. That's my last resort if nothing else works out :) The reason I don't want to do it this way is that it will expose the link to my files. – Gaurav Mantri Nov 05 '13 at 09:41

2 Answers2

2

Simply put, in my controller action I should be able to specify the URL of the file and somehow browser should force download the file [without exposing the URL of the file to the client].

You can't. If the final URL is to remain hidden, your server must serve the data, so your server must download the file from the URL.

Your client can't download a file it can't get the URL to.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
0

You can create file transfer WCF service (REST) which will stream your content from blob storage or from other sources through your file managers to client browser directly by URL.

https://{service}/FileTransfer/DownloadFile/{id, synonym, filename etc}

Blob path won't be exposed, web application will be free from file transfer issues.