I have an ASP.NET web application to download blobs from my azure storage. When I use blockBlob.DownloadToStream(fileStream); it automatically downloads it to the project location when run the web aplication in local machine. But if I want to deploy this web aplication in cloud, How can I get a dialog box to save the blobs to be dowloaded ?
There are two things you could do:
Set the content-type property of the blob to application/octet-stream or don't set the content type of the blob at all. While this approach may work in most of the browsers but not in all. IE is quite smart about this would actually try to read the file type from the file stream and decides if to display the file in the browser or to prompt "Save As".
Download the blob first on your web server and then serve that file by setting the Content Disposition response header value to something like `attachment; filename="Your file name"'.
Related
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.
I have uploaded a file on server and given a link to that file (test.txt file say) in my asp.net page. when i click on this link, it opens the content of that text file within the browser. But i want to open a dialog box so that user can save it on his local machine.
More over if file is dll type then it gives 404 error(file not found).
I tried it out in IE and Firefox and also its working fine on my local IIS but not on Server machine.
There are various ways suggested of forcing a file download to the browser in ASP.Net, and lots of examples ("asp.net file download"). Here's one: http://aspalliance.com/259
Basically, what you'l need to do is transfer the file to the browser 'in code' using Response.WriteFile() or something similar.
You'll also need to set a couple of response headers so that the browser knows this is a download as opposed to a file it should try and load: Content-Type and Content-Disposition
Personally, I'd rather zip a DLL if it is to be downloaded - after all a DLL is executable code, and could be blocked at the client side.
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
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.
We have a file upload in our ASP.NET MVC application that works fine. It engages the browser file dialog box and performs an upload on the selected file. Now, we're interested to receive the UNC path from the file (for different mapped drives) if possible. Can this be done?
What we'd like to do is if it's a non local resource, we'd like to pass up the UNC path rather upload since our server could access it much quicker.
The file input control will be able to use whatever the client computer can, be it UNC or local. The file will be uploaded via the client.
If you want to extract this path from the upload, this is not possible due to security considerations.
You may need to ask the user to input the file path to a text field in order to determine if it is local or on a network share, then decide what method to use in order to obtain the file.