3

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!

AT8500
  • 35
  • 1
  • 5
  • Javascript can't do this (for security reasons) so you will want to look into NaCl [Native Client](https://developer.chrome.com/native-client) and [Native Messaging](https://developer.chrome.com/extensions/messaging#native-messaging). – David Jun 22 '14 at 21:00
  • Thank you, David, but is it possible to do with google chrome extension which will do this file manipulation for me (for example extension monitor download, when detect targeted files it do what I want with them). I know that google chrome has chrome fileSystem and downlod API but not sure if and how it can be used for my case and if it is possible to do without any extra dialogs and inputs from usre. – AT8500 Jun 23 '14 at 06:34
  • @David See my answer - it's possible to do this in a limited fashion with `chrome.downloads` API – Xan Jun 23 '14 at 11:40

1 Answers1

2

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.

  1. After a download you initiated with chrome.downloads.download finishes, you can initiate opening it with chrome.downloads.open(downloadId).

  2. 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.

  3. 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.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • In his question, under number 2 he says "Setting default chrome download folder as that monitored folder is not options" – David Jun 23 '14 at 11:50
  • @David Which is understandable - you can't monitor the whole Downloads folder. A specific subfolder that's not written to unless specifically done like that - that's viable. – Xan Jun 23 '14 at 11:51
  • Well solution with subfolder could work but I am affraid that users could accidentally delete that folder and than it could cause lot of problems with printer. And if that happens when I am not in office whole business would stop so it is too risky. But is there any other solutions that you guys could think of it does not have to be chrome extension. Maybe to use something else like java applet or VB or something. Not that I am familiar with them but I think that I could work something out because it is very simple what I need – AT8500 Jun 23 '14 at 17:12
  • The folder will be recreated if needed automatically; you can create it manually lock its permissions down if you're worried about deletion. As for a different solution, that would probably be a new question. Good luck. – Xan Jun 23 '14 at 17:36
  • Xan can you at least sugest in what direction to look for alternative solutions? I just can't figure it out. I will accept your answer because it is one that helped me if I choose to use default download folder (with subfolder) but I just would like if it could be done without using it. So can you, if you know, point me where to look for alternatives :) – AT8500 Jun 23 '14 at 18:51