Hello,
I am trying to download a file (usually pdf) from a URL. After that I want to upload the same file through an API again. I have got the following “solution” from the API developer - however, I have no idea how to do this in n8n. Can you help me?
I have got the following code:
import requests
input_data = {
"file_url": "[[URL where the file is located]]",
"api_key": "[[Your API KEY]]",
"org_id": [[ID of the org that this could be uploaded to]]
}
# Download the file / hyrate the file
f_downloaded = requests.get(input_data['file_url'])
# Get the full url of the file
url = input_data['file_url']
# Get the file name
filename = url[url.rfind("/")+1:]
filename_small = filename.replace(".", "_small.")
# Post request to upload the file
response = requests.post('https://api.affinity.co/entity-files', auth=('',input_data['api_key']), params=({'organization_id': input_data['org_id']}), files={'file': (filename_small, f_downloaded.content, f_downloaded.headers['content-type'])})
Please help. Thank you in advance!