import requests
# The URL for the upload endpoint
url = 'http://api.knowbase.ai/api/v1/upload'
# Replace 'your_access_token_here' with the actual access token you received from the API
headers = {
'access-token': 'your_access_token_here'
}
# Replace 'path_to_your_file' with the actual file path on your system
files = {
'file': ('filename.pdf', open('path_to_your_file', 'rb'), 'application/pdf')
}
# Make the POST request to upload the file
response = requests.post(url, headers=headers, files=files)
# Check the response
if response.status_code == 200:
print("File uploaded successfully.")
print(response.json()) # This will print the response which includes the 'file_id'
else:
print("Failed to upload file.")
print(response.json()) # This will print the error message
# Don't forget to close the file if you're not using a context manager
files['file'][1].close()