Can I Upload the same file twice in a row?

I’m new to Dash and could use a sanity check for my mental model of how the Upload component works.

TL;DR: It seems that if I drop the same file into the uploader twice in a row, the upload callback is only invoked the first time. I can, however, alternate between a pair of files and the callback is invoked every time.

I’d like to be able to drop a file into the uploader and have something run on the back end every time, even if I have just dropped the same file.

Is there some way to make this happen? Perhaps some way for the handler to tell the upload component that that file has been handled and is ok to re-upload?

THANKS!


I’m the Faculty examples as an example because it displays the same behavior that I’m seeing in an app I’m building at work.

The copy of the faculty app that I’m working with has these changes, the important one is adding a print("PING...") that gets called every time the update_output callback is called

--- src/webapp/faculty.py	2020-06-03 17:23:11.678402762 +0000
+++ src/webapp/faculty.py.orig	2020-06-03 17:54:51.526428901 +0000
@@ -2,13 +2,14 @@
 import os
 from urllib.parse import quote as urlquote

+from flask import Flask, send_from_directory
 import dash
 import dash_core_components as dcc
 import dash_html_components as html
 from dash.dependencies import Input, Output
-from flask import Flask, send_from_directory

-UPLOAD_DIRECTORY = "/local_scratch/george.hartzell/tmp/app_uploaded_files"
+
+UPLOAD_DIRECTORY = "/project/app_uploaded_files"

 if not os.path.exists(UPLOAD_DIRECTORY):
     os.makedirs(UPLOAD_DIRECTORY)
@@ -83,7 +84,6 @@
 )
 def update_output(uploaded_filenames, uploaded_file_contents):
     """Save uploaded files and regenerate the file list."""
-    print("PING...")

     if uploaded_filenames is not None and uploaded_file_contents is not None:
         for name, data in zip(uploaded_filenames, uploaded_file_contents):
@@ -97,4 +97,4 @@


 if __name__ == "__main__":
-    app.run_server(debug=True, port=8888, host="172.16.193.97")
+    app.run_server(debug=True, port=8888)

If I drop a file into the upload box, my print("PING...") is invoked, it’s uploaded and added to the list. If I drop the same file, no PING.... If I drop another file, it PING's and uploads and appears in the list. If I now drop the first file again, it PING's. I can alternate back and forth between the two files.

Set’s of files behave similarly. I can drag in a set and everything works as expected. I can’t drag the same set until I’ve dragged something else.

Yeah, this looks like a bug: [BUG] dcc.Upload does not support re-upload the same file. · Issue #816 · plotly/dash-core-components · GitHub. Not sure if there is a workaround right now for the dcc.Upload component. Under the hood, we’re using GitHub - react-dropzone/react-dropzone: Simple HTML5 drag-drop zone with React.js. and so the limitation is likely in that component, but we haven’t yet investigated.

1 Like

I found a possible lead on a solution and added a few notes over in the GitHub Issue: #816, comment.

My JS skills aren’t up to testing it on my own but I’d be happy to help out if someone else can lend a hand/mentoring.

workaround here: https://github.com/plotly/dash-core-components/issues/816#issuecomment-1032635061