简体   繁体   English

使用plotly-dash上传文件

[英]Uploading files with plotly-dash

I'm making an app with plotly-dash to view *.mdf files (Python Library asammdf for loading the files). 我正在制作一个带有plotly-dash的应用程序以查看* .mdf文件(Python库asammdf用于加载文件)。 I made an Upload component ( https://dash.plot.ly/dash-core-components/upload ) to load the files. 我制作了一个Upload组件( https://dash.plot.ly/dash-core-components/upload )以加载文件。 I thought of taking the full filename to pass this to the MDF function in the asammdf library to load the file and put data in a graph. 我考虑将完整的文件名传递给asammdf库中的MDF函数,以加载文件并将数据放入图形中。 However the dash Upload component only returns the filename and not the complete path so I cannot use the MDF function on this. 但是,破折号Upload组件仅返回文件名,而不返回完整路径,因此我无法在其上使用MDF函数。 The Upload component also outputs the content of the file as a binary string but not sure how I can pass this to the MDF function. Upload组件还以二进制字符串形式输出文件的内容,但不确定如何将其传递给MDF函数。

Somebody knows a way forward for this problem? 有人知道解决这个问题的方法吗?

Actually I found out it is possible to work with the contents variable. 实际上,我发现可以使用content变量。 The MDF function (as well as most read in functions I assume) check if the input is a 'file like' object or a string. MDF函数(以及我假设的大多数读入函数)都会检查输入是否为“文件类”对象或字符串。 If it is a 'file like' object, it directly reads from this object. 如果它是一个“类似于文件”的对象,则直接从该对象读取。 The contents can be transformed as follows: 内容可以如下转换:

content_type, content_string = contents[0].split(',')
decoded = base64.b64decode(content_string)
file_like_object = io.BytesIO(decoded)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM