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

Show "Uploading" message, and setUploaded manually #125

Open
bangbaew opened this issue Jul 7, 2023 · 0 comments
Open

Show "Uploading" message, and setUploaded manually #125

bangbaew opened this issue Jul 7, 2023 · 0 comments

Comments

@bangbaew
Copy link

bangbaew commented Jul 7, 2023

My app does upload file to the backend after dragging the files to to component, I want it to show an "uploading" message first, and I want to be able to use setUploaded in my app after finish uploading to the backend.

my app

const handleUpload = (files: FileList) => {

  setUploaded(false) //<-- Show "Uploading" message

  for (let i = 0; i < files.length; i++) {
    const f = files.item(i)!
    const formData = new FormData();
    formData.append("file", f);

    axios.post(getConfigClient() + '/document/upload', formData, {
      headers: {
        "Content-Type": "multipart/form-data",
      }
    })
      .then(async _ => {
        const newDocList: AxiosResponse<Document[]> = await axios.get(getConfigClient() + `/document`, { headers: { 'Cache-Control': 'no-cache', ...getAuthHeader() }, params: { parentId: currentFolderId } })
        setUploaded(true) // <-- Show "Uploaded" message when all files completed uploading

        setDocList(newDocList)
        setFile(f);
      })
      .catch(e => {
        console.log(e)
        alert(e.response?.data)
      })
  }
};
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

1 participant