Force file download in a browser using ASP.Net MVC when the file is located on a different server without downloading it on my server first - asp.net

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?

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.

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.

Related

Are file extensions necessary for Azure blobs?

I'm using an Azure storage account to store images and files as block blobs.
Browsers seem to be able to serve images correctly without an extension as long as the content type property is set. For example this will show up as a normal image: https://navhomeprod.blob.core.windows.net/facilityroomphotos/12
Would it be better for any reason to save the blob name with an extension: https://navhomeprod.blob.core.windows.net/facilityroomphotos/12.jpg
The reason I chose not to have extensions is so that I didn't need an extension field in the database, I could just use ids to serve the images.
Simple answer is no. You don't really need to specify a file extension in order to serve images. The catch here is that content type should be set properly. Content type tells browsers how to serve the content.
Even if you have the extension set but content type not set, some browsers will not be able to serve the content in that case. I have seen many questions where Chrome prompted to download an image file instead of showing the content inline if the content-type of that image file not set properly.
One use case that I could think of where the file extension will be handy is when you download these files on your local computer. Based on the file extension, your local computer would decide the application to use to view/edit these files.

Accessing WebDav from Server Link

I've downloaded the .Net Server and ajax library
We need to be able to edit documents directly from the WebDav Server.
I've succeeded doing so with the javascript code using MicrosoftOfficeEditDocument and JavaEditDocument
I'd like to be able to have in my pages a link as follows
\server\DAV\path\file
When I place a similar link like above, it doesn't open the file. When I copy link and place in windows run command, it opens
Is it possible to have direct links to webdav storage files for opening?
Also, Is there a planned solution for the jar file running in Chrome?
I've followed the instruction for https://java.com/en/download/faq/chrome.xml#npapichrome
This allows chrome to load the jar file, but They say they stop supporting.
To open a document from a web page your link must be HTTP or HTTPS, that is start with http://server/. It would not work with a network path.
In your case URL must look like http://server/DAV/path/file.ext

HTTP auth and Flex

I have a small query. I wrote a Flex Application with PHP remoting using ZendAMF. i also made and auth system. User provides credentials and i pass them to my gateway where i have a service registered to query a SQL db and verify if the user is registered or not. Thats working perfectly. In my application i am loading MRTG graphs (PNG Files) into Image component. The GRAPHS are inside my Document Root. They are also loading well. Problem is if i type the URL path to the png file i can see it directly without any authentication. to cater that i added htaccess file to MRTG folder inside my document root. Know when i view the images inside my Flex App it asks for HTTP username and password. which i dont want.
In simple words . MRTG PNG's are inside my document root
Can i move them out of document root and still have my Flex App access them ( i tried and failed with that)
I just want the user to be able to view MRTG pngs and not directly from URL.
If you are using ZendAMF, why don't you just create a service method on your service that provides you with those images?
That way you have full control over what happens.
For example you could send them through as a byte array or a base64 encoded string, making it a lot harder to define where the image is actually stored on server disk.
Cheers

asp:FileUpload fetch the file Path

VS 2008
How to fetch the Full File path for the File Uploaded in asp.net ??
Either HTML or ASP.Net Server Control, i need to use File Upload - Browse feature and need to fetch the Complete file path.
My guess is Due to security reasons, ASP.Net does not support asp:FileUpload to deliver the Full File Path ..!
What would be the best way to get the file path ?
You can't do what you want by design (at least on modern browsers). This would be a security issue if you could.
You can read more about this here.
Snipit:
Historically, the HTML File Upload
Control () has been
the source of a significant number of
information disclosure
vulnerabilities. To resolve these
issues, two changes were made to the
behavior of the control.
To block attacks that rely on
“stealing” keystrokes to
surreptitiously trick the user into
typing a local file path into the
control, the File Path edit box is now
read-only. The user must explicitly
select a file for upload using the
File Browse dialog.
IE8 read-only File Path box
Additionally, the “Include local
directory path when uploading files”
URLAction has been set to "Disable"
for the Internet Zone. This change
prevents leakage of potentially
sensitive local file-system
information to the Internet. For
instance, rather than submitting the
full path
C:\users\ericlaw\documents\secret\image.png,
Internet Explorer 8 will now submit
only the filename image.png.

File browser control to replace <input type="file">

I'm working on an ASP.NET web application for our corporate intranet users. I have a form where a user should provide a path to the file on the local network (something like "\localServer\someFolder\someFile.ext") without uploading the actual file. The issue is that users don't want to type the whole file path and want to use some kind of visual browse dialog.
The standard HTML <input type=file> element allows to browse for a file, but most of the browsers (except for IE) don't allow to access file's full path, so I think it should be done by some external component like Silverlight, Flash, Java applet etc.
I tried to do it with Silverlight, but I'm getting a SecurityException when trying to access file's full path using Silverlight's OpenFileDialog class.
This java applet http://jumploader.com/demo_images.html seems to do something similar to what I'm looking for, but it's focused on uploading files - I only need to be able to get file's full path and pass it to the server as a string.
Any suggestions would be appreciated.
Telerik ASP.NET AJAX RadFileExplorer has the functionality you're looking for:
http://www.telerik.com/products/aspnet-ajax/fileexplorer.aspx
You can use their Custom File Content Provider to hook the GUI to your server's file system.
http://demos.telerik.com/aspnet-ajax/fileexplorer/examples/server-sideapi/dbfilebrowsercontentprovider/defaultcs.aspx
This should be possible with Flash's uploading capabilities. SWFUpload has an API that you may be able to access from JavaScript to extract the selected file name without actually uploading anything. See docs here, for example getFile():
getFile is used to retrieve a File Object from the queue. The file retrieved by passing in a file id (the id property from a file object) or a file index (the index property from a file object).

Resources