Google Chrome extension - download, move and delete files - javascript

I am trying o make app for my work (will be used only in my office) and among other things I need way to download file (it will be always one ODT and one txt document which will be initiated by clicking on button by user, on specific page - standard download) from our local server. Those two files are created on server and then sent to download to user which requested it, so that part is simple as any other web page which offers you download.
But after download is finished I need somehow:
1) automatically open ODT (openOffice writer) file, so user can continue editing it. What will happen next is not important...
2) automatically move TXT file to specific folder on users disk (this is needed because that specific folder is monitored by our special printer and whenever printer detects file in that folder it automatically starts printing). Setting default chrome download folder as that monitored folder is not options - so I NEED to move TXT file automatically after download to that monitored folder.
3) After first two actions are finished I need to clean default download folder (foldere where chrome downloads by default) because it would be full of those files and they are not needed anymore.
Now, it would be great if I could accomplish it just with javascript but as I know there is no way to manipulate files on local system without displaying dialog to user - so this is not option.
I figure it out that this part could be done by chrome extension, which is acceptable solution because this application will be used only in my office. But I am not sure how and if it is really possible to accomplish what I want so I need your help.
P.S.
It is important that after user click "Download" on page to download ODT and TXT file, there is no other windows, dialog and other "questions" by browser but everything after that should go automatically.
Thank you!

Yes, you can do those tasks with chrome.downloads API, as long as you can accept a subfolder of the Downloads folder as a target for your printer. You cannot download in an arbitrary folder, I'm afraid.
After a download you initiated with chrome.downloads.download finishes, you can initiate opening it with chrome.downloads.open(downloadId).
You can initiate a download into a subfolder by supplying a relative path to chrome.downloads.download (note the / slash instead of \): printout/file.txt.
You can remember the download id's and clean up afterwards with chrome.downloads.removeFile(downloadId).
Please take note of the permissions you need to add, they are quite fine-grained for this API.

Related

Download image in specified folder not in default browser download folder by javascript [duplicate]

I have a web application that receives a simple text file, but I need this file to be downloaded to a specific path. Meaning, when the application receives a text file, it will always be downloaded to a specific folder (for example, to C:\MyFolder). If it isn't possible, then I need to copy the file from where user has chosen to my folder.
This application is based on JavaScript.
JavaScript cannot exert any control over my (the visitor's) local filesystem. I remain in complete control of where my downloaded files go, what they are named, and indeed whether I even want to download them in the first place.
Sorry, but the best you can do is inform your users where to put the file you're offering for download. You cannot use JavaScript to choose the destination yourself.
You should be able to do this using a Java applet assuming that you have signed it. The user would be asked to allow your code to run and if allowed, you could do whatever you want: Including downloading a file to a specific location.

Is there a way to suggest a download path within a web application?

Consider the following case:
In my webpage, I have two links that are used for downloading two distinct files, one for a.css and one for a.js.
CLIENT_AAA prefers to download the a.css file into /path/to/css/ folder and a.js file to /path/to/js/ folder in his specific computer. CLIENT_BBB will probably use different folders, but it's out of our scope.
Problem is that when this user saves a.js and then downloads a.css, the browser (Chromium in my case) suggests downloading the new file to /path/to/js/ folder because that was the last folder used for a download. User needs to click up, select css folder and then save the file.
I wonder if I can "suggest" the browser for a valid download folder for that user per link, so when user clicks <a href="a.css" download>a.css</a>, browser will open /path/to/css folder and when user clicks <a href="a.js" download>a.js</a>, it will open /path/to/js folder. Is that possible?
That's totally up to the browser. There's no HTTP header to do what you're asking. You can specify the filename in Content-Disposition but that's all.
Consider that if you could nudge the browser towards a particular path, and browsers followed your suggestion, that would let bad people create downloads that overwrite system files with whatever content they want. Of course, people can still do that to themselves, but letting the server direct the browser to a particular full path would be a severe security problem.

How do I allow files to be downloaded to a folder other than the Downloads folder?

I am able to use the HTML5 Download attribute to specify a file for download to the user's declared downloads folder, but what I would like to do is allow for users to create a "portal" that specifies a directory that future files can be downloaded to.
The wording is confusing so I'll use an example:
User will be using the site to exchange source code with a coworker. However, whenever the using downloads his coworker's source code, it always defaults to his Browser designated "downloads" folder. Is it possible to have the User be able to specify on the website that he wants it downloaded to a specific directory? Namely, his workspace for whatever project he is collaborating on.
Hopefully, this is descriptive enough. I really can't find any tools for this online.
Its not possible as the download location is controller by the browser.
If you want to know more give the page a read Download A File At Different Location Using HTML5

Force ask where save file before download

I have an embedded system with a web server Mongoose, I have to allow the client to download some log files generated at runtime, I have a problem during the download, in practice, the browser first downloads the file and then asks where to save the file .
The behavior is unpleasant because the download takes a few seconds and the client does not understand what's going on.
Is there any option, for example, in the header of the file, to force the browser to ask before making the download where to save the file?
Thanks.
it is not up to you to decide how the client's browser is behaving.
if the browser is set to save the file automatically in a specific place, then there is nothing you can do.
your only workarounds is to either upload your file somewhere and suggest the viewer to right-click a download link that points to the file, it will open the dialog,
or suggest the viewer to change browser settings,
or write a browser extension that does that and offer viewers to install it.

Local html file on CD can open links with default program

For example I have a html file :
test
On chrome - when clicked the file downloaded to default directory
On IE - when clicked asks to open or download
how somehow when clicked, automatically open it with default program in windows
I dont have any references but i think youre not in controll of that behaviour. You can probably as well configure chrome the way it asks you before downloading and vice a verse configure IE to not ask but download the files in a certain directory.
Maybe there is a possiblity to have a java script code running on page load that initiates a download directly without any notification to the user but that wont run in any cases as well (since youre not in controll if someone switches off java script).

Categories

Resources