test_zadanie_S3/test.py
2024-03-23 14:09:12 +03:00

20 lines
649 B
Python

import requests
def send_image(image_path: str, target_width: int) -> None:
with open(image_path, 'rb') as file:
file_data = file.read()
url = f'http://localhost:8000/api/upload_image/?target_width={target_width}'
response = requests.post(url, files={'file': file_data})
if response.status_code == 200:
link = response.json()["resized_image_link"]
print("Файл успешно отправлен!", link, sep="\n")
else:
print("Ошибка при отправке файла:", response.status_code, response.json()["detail"])
if __name__ == "__main__":
send_image("image.png", 300)