Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file pasting #12

Open
Hattorius opened this issue Oct 22, 2024 · 1 comment
Open

Add file pasting #12

Hattorius opened this issue Oct 22, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Hattorius
Copy link
Owner

It should be possible to paste a file into the website (just like how imgur.com does). These files get handled just like any other.

Expected features

  • After the website opens you should directly be able to ctrl+V a file into the page (no click required)
  • These pasted files could be literal copied images (from other sources) or copied from the file explorer
  • These files should be handles just like any other file
@Hattorius
Copy link
Owner Author

This doesn't have to be too hard. A simple implementation could be:

document.addEventListener('paste', function (event) {
    if (event.clipboardData && event.clipboardData.items) {
        for (let i = 0; i < event.clipboardData.items.length; i++) {
            let item = event.clipboardData.items[i];
            
            // Check if the item is a file
            if (item.kind === 'file') {
                // Get the file as a File object
                let file = item.getAsFile();

                // Use the File object
                if (file) {
                    handleFile(file);
                }

                // Multiple files? Try zipping them?
            }
        }
    }
});

At the end the "Multiple files? Try zipping them?" is a reference to #11

@Hattorius Hattorius added the enhancement New feature or request label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant