Users can upload and download files on the web using Simplex. This is useful for uploading images to pages like real estate listings or for downloading files from medical records or EHR systems.

Uploading Files

To upload files, we provide the click_and_upload endpoint and SDK function, which takes in an element description and a file to upload. The element description must be an element that would typically open the operating system file upload dialog.

In this example, we have to run click_and_upload with the “Click or drag and drop” section and our desired file. We’re using a file called “logo.png” here.

upload_file.py
from simplex import Simplex
import os
simplex = Simplex(api_key="your_api_key")
simplex.create_session(proxies=False)
simplex.goto("https://simplex.sh/upload-example.html")
simplex.click_and_upload("Click or drag and drop an image", "logo.png")
print(simplex.extract_text("File name"))

Downloading Files

To download files, we provide the click_and_download endpoint and SDK function, which takes in an element description. The element description must be an element that would typically download a file to your computer.

In this (slightly contrived) example, we have to first press the “Select Action” button, then run click_and_download with the “Download Logo” button.

download_file.py
from simplex import Simplex
import base64
import os
simplex = Simplex(api_key="your_api_key")
simplex.create_session(proxies=False)
simplex.wait(3000) # wait so we have time to open the URL link
simplex.goto("https://simplex.sh/download-example.html")
simplex.click("Select Action")
b64_str, file_name = simplex.click_and_download("Download Logo")
# Write bytes to file
with open(file_name, "wb") as f:
    f.write(base64.b64decode(b64_str))

You should now see a logo-{timestamp}.png file in the directory you ran the script from.