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

How to get updated meta.percent that comes from fileWithMeta? #182

Open
humbertocruz opened this issue Jan 20, 2022 · 1 comment
Open

How to get updated meta.percent that comes from fileWithMeta? #182

humbertocruz opened this issue Jan 20, 2022 · 1 comment

Comments

@humbertocruz
Copy link

How to update meta.percent that comes from fileWithMeta? I building a custom progress.

onChangeStatus is called on "uploading" and stops until "done", meas 0% and 100%

Thanks

@virginiadewangga
Copy link

virginiadewangga commented Jan 3, 2023

Hay, this is how I do it. Hope its help

const Standard = () => {

  const [_updatePreview, setUpdatePreview] = useState<any>({})

  const getUploadParams: IDropzoneProps['getUploadParams'] = () => {
    return { url: 'https://httpbin.org/post' }
  }

  const handleChangeStatus: IDropzoneProps['onChangeStatus'] = (file, status, allFiles) => {
    if (file.xhr) {
      file.xhr.upload.onprogress = function (e) {
        setUpdatePreview({
          total: e.total,
          loaded: e.loaded,
        })
      }
    }
    setUpdatePreview(status);
  }

  const handleSubmit: IDropzoneProps['onSubmit'] = (files, allFiles) => {
    console.log(files.map(f => f.meta))
    allFiles.forEach(f => f.remove())
  }

  return (
    <Dropzone
      getUploadParams={getUploadParams}
      onChangeStatus={handleChangeStatus}
      onSubmit={handleSubmit}
      styles={{ dropzone: { minHeight: 200, maxHeight: 250 } }}
    />
  )
}

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

2 participants