0

I read a lot about this topic but they are all created long ago and saying it's not possible . So I'm wondering is it possible to manipulate with the root of the downloads folder , without jeopardizing the clients privacy ?... because clearly that's the main issue of this problem .

Or does anyone have any other idea on how to cross this problem of not storing the files into specified browser download folder ?

poke
  • 369,085
  • 72
  • 557
  • 602
  • 2
    Web applications don’t have access to the user’s file system. So no, you cannot modify files, regardless of where they are. The only thing you can do is offer a download which the user can then *choose* do save somewhere. – poke Dec 16 '17 at 22:05
  • That might do , can you give me some leads ? If you can – Алекса Јевтић Dec 16 '17 at 22:07
  • 1
    Possible duplicate of [Create a file in memory for user to download, not through server](https://stackoverflow.com/questions/3665115/create-a-file-in-memory-for-user-to-download-not-through-server) – poke Dec 16 '17 at 22:07
  • 1
    You can generate a txt file client side -- no problem. You cannot do anything to the user's file system, only allow them to save it themselves. – tech4him Dec 16 '17 at 22:16
  • Yep , I've seen FileSaver.js and Blob , with that it's easy to create a file . so the dialog in which client can pick the location where to store the file is possible ? – Алекса Јевтић Dec 16 '17 at 22:19
  • Depends on the browser and the user's configuration. Safari, for example, defaults to the `/Downloads` folder, but there's an option to ask for a destination with each file. A web page doesn't have access to this preference. – Stephen Thomas Dec 16 '17 at 22:27
  • there are many other ways to store information - cookies, `localStorage`, indexDB https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API – Slai Dec 16 '17 at 22:46

1 Answers1

1

Here are a couple of ways to create files using a website:

  1. Create the file virtually and then have the user download the file. You could also create a single zip file with an entire folder structure to create a folder structure in the download folder once it's unzipped.

  2. Use the Filesystem API which has terrible support, I think it's pretty much just Chrome that supports it and it's severely limited. Not recommended.

  3. Use something like Emscripten to have a nicer Filesystem API available. That way you can create the folders and files easily before you, you guessed it, create a zip file that the user downloads. Emscripten has a virtual filesystem that you handle using C++ standard file input/output.

  4. Create an extension for the target browser(s) that the user has to install before you can create files in their filesystem. API's for this is somewhat limited but could be a solution for you since it allows direct editing of files as opposed to first zipping and downloading/unzipping a zip file.

  5. Create your website as a Cordova application and use its filesystem API. Note that this doesn't let your website use the users filesystem, but it allows you to easily distribute your website in the form of an installable app that can then use native tech to interact with the filesystem.

There may be more solutions but these are the ways that came to mind. The reason it's a bit problematic to interact with the filesystem is for obvious security issues that arise when a malicious site could then just create a virus in your filesystem and then request that it gets opened by another program on your computer and if the user then presses accept, BAM, virus infested computer.

Simon Hyll
  • 3,265
  • 3
  • 24
  • 44