[英]How to get the path of a file upload on ipywidgets?
How can I get the actual path of the file uploaded from the FileUpload
widget?如何获取从
FileUpload
小部件上传的文件的实际路径? In my case, I am uploading a binary file and just need to know where it is so I can process it using an internal application.就我而言,我正在上传一个二进制文件,只需要知道它在哪里,这样我就可以使用内部应用程序处理它。
When I iterate on the FileUpload
value I see there is a file name as a key and a dict
as the value:当我迭代
FileUpload
值时,我看到有一个文件名作为键,一个dict
作为值:
up_value = self.widgets['file_upload'].value
for file_name, file_dict in up_value.items():
print(file_dict.keys()) # -> dict_keys(['metadata', 'content'])
print(file_dict['metadata'].keys()) # -> dict_keys(['name', 'type', 'size', 'lastModified'])
I know the content of the file is uploaded but really don't need that.我知道文件的内容已上传,但真的不需要。 Also not sure how I would pass that content to my internal processing application.
也不确定如何将该内容传递给我的内部处理应用程序。 I just want to create a
dict
that stores the filename as a key and the file path as the value.我只想创建一个将文件名存储为键和文件路径作为值的
dict
。
thx谢谢
Once 'uploaded', the file exists as data in memory, so there is no concept of the originating 'path' in the widget.一旦“上传”,该文件作为数据存在于 memory 中,因此小部件中没有原始“路径”的概念。
If you want to read or write the file, access the up_value.value[0].content
attribute.如果要读取或写入文件,请访问
up_value.value[0].content
属性。 Your processing application needs to be able to handle bytes input, or you could wrap the data in a BytesIO object.您的处理应用程序需要能够处理字节输入,或者您可以将数据包装在 BytesIO object 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.