Skip to content

Commit 0cdae8f

Browse files
authored
Merge pull request #2724 from jtpio/file-upload-content
Consolidate FileUpload value by using a single top-level dict
2 parents 5042b8c + 4030d4c commit 0cdae8f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

docs/source/examples/Widget List.ipynb

+6-3
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,10 @@
10151015
"uploader.value\n",
10161016
"#=> [\n",
10171017
"#=> {\n",
1018-
"#=> 'metadata': {'name': 'example.txt', 'type': 'text/plain', 'size': 36, 'lastModified': 1578647380733}, \n",
1018+
"#=> 'name': 'example.txt',\n",
1019+
"#=> 'type': 'text/plain',\n",
1020+
"#=> 'size': 36,\n",
1021+
"#=> 'lastModified': 1578647380733, \n",
10191022
"#=> 'content': <memory at 0x10c1b37c8>\n",
10201023
"#=> }\n",
10211024
"#=> ]\n",
@@ -1061,9 +1064,9 @@
10611064
" \n",
10621065
"The `FileUpload` changed significantly in ipywidgets 8:\n",
10631066
" \n",
1064-
"- The `.value` traitlet is now a list of dictionaries with a `metadata` and `content` entry, rather than a dictionary mapping the uploaded name to the content. To retrieve the original form, use `{f[\"metadata\"][\"name\"]: f[\"content\"].tobytes() for f in uploader.value}`.\n",
1067+
"- The `.value` traitlet is now a list of dictionaries, rather than a dictionary mapping the uploaded name to the content. To retrieve the original form, use `{f[\"name\"]: f[\"content\"].tobytes() for f in uploader.value}`.\n",
10651068
"- The `.data` traitlet has been removed. To retrieve it, use `[f[\"content\"].tobytes() for f in uploader.value]`.\n",
1066-
"- The `.metadata` traitlet has been removed. To retrieve it, use `[f[\"metadata\"]. for f in uploader.value]`.\n",
1069+
"- The `.metadata` traitlet has been removed. To retrieve it, use `[{k: v for k, v in f.items() if k != \"content\"} for f in w.value]`.\n",
10671070
"</div>"
10681071
]
10691072
},

packages/controls/src/widget_upload.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class FileUploadView extends DOMWidgetView {
9696
.then(contents => {
9797
const value = contents.map(c => {
9898
return {
99-
metadata: c.metadata,
99+
...c.metadata,
100100
content: c.buffer
101101
};
102102
});

0 commit comments

Comments
 (0)