MCPcopy Index your code
hub / github.com/pywebio/PyWebIO / put_file

Function put_file

pywebio/output.py:930–956  ·  view source on GitHub ↗

Output a link to download a file To show a link with the file name on the browser. When click the link, the browser automatically downloads the file. :param str name: File name downloaded as :param content: File content. It is a bytes-like object :param str label: The label of the

(name: str, content: bytes, label: str = None, scope: str = None,
             position: int = OutputPosition.BOTTOM)

Source from the content-addressed store, hash-verified

928
929
930def put_file(name: str, content: bytes, label: str = None, scope: str = None,
931 position: int = OutputPosition.BOTTOM) -> Output:
932 """Output a link to download a file
933
934 To show a link with the file name on the browser. When click the link, the browser automatically downloads the file.
935
936 :param str name: File name downloaded as
937 :param content: File content. It is a bytes-like object
938 :param str label: The label of the download link, which is the same as the file name by default.
939 :param int scope, position: Those arguments have the same meaning as for `put_text()`
940
941 Example:
942
943 .. exportable-codeblock::
944 :name: put_file
945 :summary: `put_file()` usage
946
947 content = open('./some-file', 'rb').read() # ..doc-only
948 content = open('README.md', 'rb').read() # ..demo-only
949 put_file('hello-world.txt', content, 'download me')
950 """
951 if label is None:
952 label = name
953 output = put_buttons(buttons=[label], link_style=True,
954 onclick=[lambda: download(name, content)],
955 scope=scope, position=position)
956 return output
957
958
959def put_link(name: str, url: str = None, app: str = None, new_window: bool = False, scope: str = None,

Callers 5

targetFunction · 0.85
basic_outputFunction · 0.85
show_popupFunction · 0.85
output_widgetsFunction · 0.85
show_popupFunction · 0.85

Calls 2

put_buttonsFunction · 0.85
downloadFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…