Invoke File save as prompt while Downloading in ExtJS - file

I want to invoke the file save as prompt while allowing the user to download a file in ExtJS from a URL.
Basically the idea is to allow the user to change the file name and select his desired location before saving the file on their machine.
Is there any way I could do this?
I do not want to use:
A server side code to send the headers.
Nor do I want to use the Flash-based Downloadify library to do this.
Also, <a> tag's "download" attribute does download the file, but it does not prompt the dialog box if the browser settings are not set right.
Is there any way apart from the above where we could handle the file download in our application?

No, it cannot be done with javascript alone due to the security restrictions of the contemporary browsers. You can read files but I have no knowledge of a way to save files directly from the javascript alone.
If your "I do not want tos" are not that strict, here you can find an example of file downloading. The essence is to send "Content-Disposition: attachment" header.

Related

dart: How to save a file?

I need to save the file that is on my hard drive.
File address: /home/mk/proj1/1.txt
Program address: /home/mk/proj2/
I try to save:
new dom.AnchorElement(href: '/home/mk/proj1/1.txt')
..setAttribute("download", '1.txt')
..click();
Displays information about saving, but writes: Failed! No file.
How to save a file?
There is not really a way to save a file in the browser (except perhaps limited support for temporary files)
You can search for JavaScript solutions. They will be quite similar for Dart in the browser.
For example JavaScript: Create and save file
If you want to store a file on the client machine, you can provide a download link.
See also How to force a Download File prompt instead of displaying it in-browser with HTML?
To provide a download link for data that is available in the browser clients code instead of a server file, you can use a data url.
See also https://stackoverflow.com/a/29691487/217408

How does the .gdoc format work?

If you work with Google Docs your first file format is .gdoc / .gsheet / .gwhatever
What I want to understand is, how this file format works. When you open a .gdoc you basically open the browser and go to a specific URL. So is a .gdoc just a .html-file with a changed file extension?
I would like to build something similiar: A rich-text-editor which saves the content in my own file format, that you can download and if you open the file, the browser opens and links to a specific URL.
BTW: I opened a .gsheet in a text editor and found this source code:
{"url": "https://docs.google.com/a/test.com/spreadsheet/ccc?key=01234567898765432123456789&usp=docslist_api", "resource_id": "spreadsheet:0A12345B678HJK9TZPL9078767"}
*Changed the URL a bit ;)
.gdoc and .gsheet files don't contain html, but JSON. These extensions are usually linked to the Google Drive application, which just reads the file and opens the URL with your standard browser.
If you're going to implement something like this yourself, you can go the same route: let the user install a program that handles your own files and start e.g. the browser.
Another way is to just use standard shortcuts; or use can use html files (maybe with another file extension if you link this extension to the standard browser) which just redirects to your target url.
in response to your comments:
to create a simple shortcut, you'll have to generate a file with the following content:
[InternetShortcut]
URL=your.url.com
and save it as YourFileName.YourExtension.url. Note that the "real" file-extension is .url. When saved to disk, windows explorer will usually hide the .url part (regardless of the Hide known file types setting). When the user starts this file, it will just open your.url.com. Chrome provides an API to create and save files client-side, but I don't know about other browsers. Probably you'll have to use a third-party library for creating the files (if you want to do this client-side).
Note this is a Windows-only solution. I don't know how you would handle this on Mac OS.

How do you link to a file such that it will download rather than render in browser?

I want people to be able to click my link and download my file. But when I link to the file download on my site, it just brings them to the code for the file. I am trying to upload a .cpp file (c plus plus). It's in my downloads folder but when I link to there it displays the .cpp file rather than download it.
Any help is appreciated.
You can set the Content-Disposition header to "attachment" in your HTTP response. If you let me know what server platform, I'll try to give more detail.
You will have to write some code to set the HTTP response header ContentType to "application/x-force-download". This tells the browser what you really want is a file download, instead of the default action (file open). You will also need to set the ContentLength header. This allows the browser to display a progress bar.
If you use ASP.NET, there are some commercial product for this purpose:
http://www.essentialobjects.com/Products/EOWeb/Downloader.aspx
It basically does what stated above with a few extra features.
That's because the browser knows how to read the file - you could ask users on the page to right click on the link and click "Save Target As" rather than just having a link.

IE file download box get location

i am currently working on a issue where i need to get location of the file downloaded.First let me explain the scenario.
I placed a link in my page and when user clicks the link it shows file download dialog with open/save/cancel options in IE.Now when the user clicks on the save button and choose a location to save the file i need to get that file saved location using whatever options possible.
Thanks!
I do not think you can... at least not easy. This runs on the client, and for security reasons you can not acces the client's filesystem with javascript.
Maybe it is however possible using a flash or silverlight plugin, as the user can allow access from within these applications to the local filesystem. It might be very difficult tho...
The browser will not allow you to access information about the clients filesystem.

different way to upload file

Is there a way to upload a file by copying a file from the desktop and pasting it into a text input which will obviously just display the filename, rather than going through the file window and selecting the file?
Talking about web applications, that could be possible if you install a custom ActiveX object or even a Java applet, or maybe trying to exploit a browser vulnerability. But, most straight way to do that will be using a <input type='file'>
For client applications, you can do that, if your current user have appropriate permissions, like accessing your file system and accessing your web server through HTTP.
Anyways, you must provide more details to get more concrete answers.
I think this is not possible and should not be possible as this is a security issue. Consider the following scenario:
A malicious site example.com shows you a harmless looking form where they have hidden such a file upload textfield with the already inserted value '/etc/passwd'. They have used either a hidden_field or just display:none with CSS.
You fill in the form and submit without knowing you have also sent a file.

Resources