question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Save images directly to native file system

See original GitHub issue

Motivation

With the Native File System API (now implemented in Chromium-based browsers), it is possible to open and save files directly to the native file system. This would allow SVG-edit to have a much better edit-save cycle, like any desktop editor.

Current behavior

Clicking SVG-edit > Save Image results in a file called “icon (x).svg” downloaded to my computer. Clicking it again results in a file called “icon (x+1).svg” being downloaded to my computer.

Desired behavior

Clicking SVG-edit > Save Image should result in the file that I opened natively to be saved to my file system. Note that for files not originally opened from the native file system, you will have to ask the user where they would like to save the file.

Steps to implement:

  1. Start using await window.showOpenFilePicker() if it’s supported by the browser, instead of the standard mechanism. Remember the file handle.

  2. On saving, if a file handle exists, for this image, then upon Save, attempt to create a writable stream from it:

        const writableStream = await fileHandle.createWritable();
        writableStream.write(someArrayBuffer);
        writableStream.close();

On first save, this will ask the user for permissions for the browser to save the file. Subsequent saves in that session will work just like any other editor.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jfhenoncommented, Jul 30, 2021

@codedread I did a quick test in the branch https://github.com/SVG-Edit/svgedit/tree/test-native-file-api This is working very well. Things to watch:

  • When you refresh the page, the filehandle is lost (needs to be saved)
  • We need a “save as…” option to be consistent
  • Safari does not support this API for now (but we could use https://github.com/GoogleChromeLabs/browser-fs-access that proposes a fallback when the API is not supported).

Thank you for the suggestion. I wish to include this in V7 definitely.

0reactions
jfhenoncommented, Aug 20, 2021

We will look into the native file system approach in V7. I think we will make it our standard approach and keep the old way as a plugin to be used for old browsers. However, I want also to test out the GoogleChromeLabs/browser-fs-access library if this helps to include Safari in the supported browsers. More and more, we will use modern approach in svgedit that may limit old browser support but offer a much better user experience. Obviously, we will keep older version of svgedit available for old browsers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Saving Photos to the Filesystem | Ionic Documentation
There we go! Each time a new photo is taken, it's now automatically saved to the filesystem.
Read more >
React-native-android - How to save an image ... - Stack Overflow
I request an image from the server, receive a base64 and I then save it to the Pictures directory in the android fs....
Read more >
How to Save Files to a Device Folder using Expo and React ...
Save files to a device's internal storage so that it's publicly visible to other apps with one line of code.
Read more >
Save an image to MacOS file system with SwiftUI
This article demonstrates how to use NSSavePanel to get the URL for the file to be saved and use NSBitmapImageRep to save a...
Read more >
The File System Access API: simplifying access to local files
The File System Access API allows web apps to read or save changes ... file save or file open dialog in the default...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found