Skip to content

Commit

Permalink
Merge pull request #2724 from jtpio/file-upload-content
Browse files Browse the repository at this point in the history
Consolidate FileUpload value by using a single top-level dict
  • Loading branch information
jasongrout authored Jan 11, 2020
2 parents 5042b8c + 4030d4c commit 0cdae8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions docs/source/examples/Widget List.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,10 @@
"uploader.value\n",
"#=> [\n",
"#=> {\n",
"#=> 'metadata': {'name': 'example.txt', 'type': 'text/plain', 'size': 36, 'lastModified': 1578647380733}, \n",
"#=> 'name': 'example.txt',\n",
"#=> 'type': 'text/plain',\n",
"#=> 'size': 36,\n",
"#=> 'lastModified': 1578647380733, \n",
"#=> 'content': <memory at 0x10c1b37c8>\n",
"#=> }\n",
"#=> ]\n",
Expand Down Expand Up @@ -1061,9 +1064,9 @@
" \n",
"The `FileUpload` changed significantly in ipywidgets 8:\n",
" \n",
"- 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",
"- 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",
"- The `.data` traitlet has been removed. To retrieve it, use `[f[\"content\"].tobytes() for f in uploader.value]`.\n",
"- The `.metadata` traitlet has been removed. To retrieve it, use `[f[\"metadata\"]. for f in uploader.value]`.\n",
"- 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",
"</div>"
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/controls/src/widget_upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class FileUploadView extends DOMWidgetView {
.then(contents => {
const value = contents.map(c => {
return {
metadata: c.metadata,
...c.metadata,
content: c.buffer
};
});
Expand Down

0 comments on commit 0cdae8f

Please sign in to comment.