Using the API to upload files

I successfully created a new record in a table called “tbl_Product” using Python via Bubble API. However, I’m having trouble uploading files into that record.
I understand there’s a special endpoint for file upload but I cannot seem to find it.
Appreciate any help / working example.

Thanks in advance!
Yoel

See this post by @aaronsheldon.

Thanks Vladmir. Is there a Python version? Also I don’t understand the attach_to parameter, I originally gave it a table name.
Here’s my code in Python where my api_url is:
f"https://MY_APP_NAME.bubbleapps.io/version-test/api/1.1/file"
(not that I tried several other things instead of /file at the end but none of them worked)

def upload_image_to_bubble(api_root_url, table_name, api_token, image_path):

  headers = {
      "Authorization": f"Bearer {api_token}",
      "Content-Type": 'application/octet-stream'
  }
  
  with open(image_path, 'rb') as image_file:
      encoded_string = base64.b64encode(image_file.read())
  
  # Prepare the payload for the image upload
  image_data = {
      "name": image_path.split('/')[-1],
      "contents": encoded_string,
      "private": True,
      "attached_to": table_name
  }
  response = requests.post(api_root_url, headers=headers, data=image_data)