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

Example code for uploading files #58

Closed
satyajitghana opened this issue Dec 25, 2020 · 6 comments
Closed

Example code for uploading files #58

satyajitghana opened this issue Dec 25, 2020 · 6 comments

Comments

@satyajitghana
Copy link

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 ?

@cybertaxi
Copy link

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.

@StarStuff15
Copy link

StarStuff15 commented Jan 11, 2021

how to define action in js
I'm stuck from two days.

@satyajitghana
Copy link
Author

@cybertaxi thanks !

but can we make it drag and drop ? something like a drop zone for file upload ?

@satyajitghana
Copy link
Author

@StarStuff15 you mean custom actions ? have you gone through https://chonky.io/docs/2.x/file-actions/custom-actions, it's pretty much explained

@TimboKZ
Copy link
Owner

TimboKZ commented Feb 9, 2021

Hey @satyajitghana, Chonky doesn't currently provide drop zone functionality, but it should work with any of the existing drop zone React libraries.

@TimboKZ TimboKZ closed this as completed Feb 9, 2021
@satyajitghana
Copy link
Author

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

aidinabedi pushed a commit to AnimechTechnologies/Chonky that referenced this issue Dec 12, 2023
Bumps [tough-cookie](https://github.com/salesforce/tough-cookie) from 4.1.2 to 4.1.3.
- [Release notes](https://github.com/salesforce/tough-cookie/releases)
- [Changelog](https://github.com/salesforce/tough-cookie/blob/master/CHANGELOG.md)
- [Commits](salesforce/tough-cookie@v4.1.2...v4.1.3)

---
updated-dependencies:
- dependency-name: tough-cookie
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants