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.

Example code for uploading files

See original GitHub issue

From the documentation https://chonky.io/docs/2.x/file-actions/built-in-actions i can see that ChonkyActions.UploadFiles just adds a button to the UI and we have to define the actions related to it, but i am finding it a little difficult on how to actually define that actions, can we have some starter/example code for handling the upload button ?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
cybertaxicommented, Jan 7, 2021

I came across this case too, let me try to help you out with this one. If we look at https://chonky.io/docs/2.x/file-actions/action-handler we understand that we can write our own handler functions based on Chonky action id, ChonkyActions.UploadFiles.id. I’m using TS for Chonky.

First we need to define the default actions (which you should have alrdy done to see the upload button):

    //enable some default actions you want in Chonky
    const setFileActions : FileAction[] = [
        ChonkyActions.UploadFiles
    ];

Then, define the handlers for ChonkyActions.UploadFiles

    //Define the handlers functions for the chonky actions.
    const handleFileAction : FileActionHandler = useCallback(
        (data) => {
            if (data.id === ChonkyActions.OpenFiles.id) {
               //do openfiles
            }

            //upload files
            if(data.id === ChonkyActions.UploadFiles.id) {
                console.log('Start Uploading files here....')
            }
        },
        [setKeyPrefix]
    );

Not sure if this is a neater way of working on it, if there’s feel free to comment on this. I hope it helps you.

0reactions
satyajitghanacommented, Jul 20, 2021

For anyone looking for example implementation with drag-n-drop: https://github.com/ProjektTejas/tejas-web/blob/master/components/dataset.tsx

Read more comments on GitHub >

github_iconTop Results From Across the Web

PHP File Upload - W3Schools
With PHP, it is easy to upload files to the server. However, with ease comes danger, ... The "upload.php" file contains the code...
Read more >
HTML File Upload Tutorial with Example • Fileschool - Filestack
A basic tutorial on how to upload a file with an HTML form. Includes a code example and discusses some options for how...
Read more >
PHP - File Uploading - Tutorialspoint
PHP - File Uploading, A PHP script can be used with a HTML form to allow users to upload files to the server....
Read more >
How to Upload a File in PHP (With an Example) - Code
We're going to create two PHP files: index.php and upload.php. The index.php file holds code which is responsible for displaying the file upload...
Read more >
Uploading Files - Happy Coding
That's because file uploading requires slightly more complicated code than handling basic text input. This tutorial goes through what we need to do...
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