Share files with a browser¶
Use Client.share() to publish
files at a browser-download URL. Start the client first and set advertise_host
to this machine’s LAN IP address so another device can reach the URL.
Python¶
This publishes one file and approves each browser download request:
from pathlib import Path
from localsend import Client, ShareRequest
def approve(_request: ShareRequest) -> bool:
return True
with Client(
"My computer",
advertise_host="192.168.1.10",
on_share_request=approve,
) as client:
url = client.share([Path("report.pdf")])
print(url)
input("Open the URL in a browser. Press Enter to stop. ")
Open the printed URL in a browser on another device connected to the same
network. Keep the process running while downloads are in progress. Pass
pin="123456" to Client to require a browser PIN.
on_share_request receives a ShareRequest
and must return True to authorize the browser download. Browser sharing
sessions expire after five minutes by default. See the
Public API for authorization and configuration details.