Dash Callback to detect and delete uploaded folders if a user leaves a specific page and fail to submit

Scenario:
I’m developing a Dash app that generates a new directory with unique ID, that allows users to upload and submit files to the directory. Sometimes, users may not click the submit button after uploading files to the directory. They will navigate to another page or close the browser.

Questions:

  • How do we alert the user that “Do you still want to submit the files?” before they navigate to another page or close the browser?
  • If the user navigates away from the upload page without submitting, how do we create callbacks to detect that and remove the folder created + files uploaded?

Hello @foongminwong,

Welcome to the community!

Sounds like you need to use something like this:

Listen to the beforeunload event, and have some if clauses around whether the user uploaded and submitted and make sure that the href is the target page to which you are referring.