1

I'm working on an offline application in Javascript that will convert a <div> to <canvas> and save it as an image to a location in local disk.

I'd prefer if the saving has no dialog and to save to the same location (set in configuration) every time.

I'm still going through the documentation on Cache API but there doesn't seem to be any answers in regards to setting absolute paths. All the examples show relative paths. I'd like to set it to something like C:/Users/Work/Presentation/file1.jpg, and have it overwrite itself every save.

Is this possible with Cache API or is there another offline storage API (localstorage won't work because it only stores k-v pairs) that would better suit this use case? Is there a library that already exists to make this implementation easier?

  • 5
    Browser doesn't provide file write access for obvious security reasons – charlietfl Apr 10 '19 at 00:40
  • @charlietfl you mean for all browsers? isn't chrome's `filesystem` api able to do this? – I should change my Username Apr 10 '19 at 01:02
  • 1
    No. There is no way a browser will allow you to programmatically store something into the disk to a specific path. Even the [docs of `FileSystem` API](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem) says "This interface will not grant you access to the users filesystem". – yqlim Apr 10 '19 at 01:34
  • [Extensions can.](https://developer.chrome.com/apps/fileSystem) – Kaiido Apr 10 '19 at 01:40

2 Answers2

0

Why not save the image data as a base-64 encoded image or a BLOB in localStorage? And deal with encoding/decoding in your code?

You can try these packages:

https://www.npmjs.com/package/base64-img

https://www.npmjs.com/package/blob-util

And, Yes. You should change your Username. ;)

Jonathan Rys
  • 1,782
  • 1
  • 13
  • 25
0

Have you tried PouchDB, via their home page.

PouchDB was created to help web developers build applications that work as well offline as they do online.


It enables applications to store data locally while offline, then synchronize it with CouchDB and compatible servers when the application is back online, keeping the user's data in sync no matter where they next login.

Dehan
  • 4,818
  • 1
  • 27
  • 38