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)
| 928 | |
| 929 | |
| 930 | def 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 | |
| 959 | def put_link(name: str, url: str = None, app: str = None, new_window: bool = False, scope: str = None, |
no test coverage detected
searching dependent graphs…