{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `ui.download`\n", "\n", "## 下载\n", "\n", "用于触发文件、URL 或字节的下载的函数。\n", "\n", "- `src`:目标URL、应下载的文件的本地路径或原始数据\n", "- `filename`:要下载的文件的名称(默认:服务器上的文件名)\n", "- `media_type`:要下载的文件的媒体类型(默认:`\"\"`)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "ui.button('Logo', on_click=lambda: ui.download('https://nicegui.io/logo.png'))\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 从内存中下载原始字节\n", "\n", "下载函数也可用于从内存中下载原始字节。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "ui.button('Download', on_click=lambda: ui.download(b'Hello World', 'hello.txt'))\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "ai", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }