boreavo's picture
update
bac48a1
Raw
History Blame Contribute Delete
955 Bytes
import requests
import os
"""
Uploads an image to Placid App and returns the URL of the processed image.
Parameters:
- api_key (str): Your Placid API key.
- image_path (str): The file path to the image you want to upload.
Returns:
- str: URL of the processed image.
"""
api_key = "placid-jza5wyzybmjyf0oe-rponxsufgssdygqk"
def uploadImages(image_files):
files = []
for index, file_tuple in enumerate(image_files):
file_path = file_tuple[0]
# Open the file in binary mode and include it in the list
files.append(('file'+str(index), (file_path, open(file_path, 'rb'), 'image/png')))
url = "https://api.placid.app/api/rest/media"
headers = {
"Authorization": f"Bearer {api_key}"
}
response = requests.post(url, headers=headers, files=files)
print(response)
data = response.json()
file_urls = [item["file_id"] for item in data["media"]]
print(data)
return file_urls