Skip to content

Commit

Permalink
Fix bug where same file could not be reuploaded (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-to authored Oct 15, 2024
1 parent 9bbb62e commit 0278d91
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mesop/components/uploader/e2e/uploader_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
@me.stateclass
class State:
file: me.UploadedFile
upload_count: int = 0


@me.page(path="/components/uploader/e2e/uploader_app")
Expand All @@ -26,6 +27,7 @@ def app():
me.text(f"File name: {state.file.name}")
me.text(f"File size: {state.file.size}")
me.text(f"File type: {state.file.mime_type}")
me.text(f"Upload count: {state.upload_count}")

with me.box(style=me.Style(margin=me.Margin.all(10))):
me.image(src=_convert_contents_data_url(state.file))
Expand All @@ -34,6 +36,7 @@ def app():
def handle_upload(event: me.UploadEvent):
state = me.state(State)
state.file = event.file
state.upload_count += 1


def _convert_contents_data_url(file: me.UploadedFile) -> str:
Expand Down
10 changes: 10 additions & 0 deletions mesop/components/uploader/e2e/uploader_test.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions mesop/components/uploader/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export class UploaderComponent {
userEvent.setKey(this.key);
userEvent.setBytesValue(uploadEvent.serializeBinary());
this.channel.dispatch(userEvent);

// Reset the uploaded file, so that the same file path can be reselected.
target.value = '';
}

getStyle(): string {
Expand Down

0 comments on commit 0278d91

Please sign in to comment.