About Checking File Types of Remote Files
You can check the file type of a remote file using the requests
and filetype
libraries:
import requests
import filetype
from django.core.files.uploadedfile import SimpleUploadedFile
response = requests.get("https://example.com/logo12345")
if response.status_code == requests.codes.OK:
kind = filetype.guess(response.content)
logo = Logo.objects.create(
image=SimpleUploadedFile(
name=f"logo.{kind.extension}",
content=response.content,
content_type=kind.mime,
),
)
Also by me
Django Paddle Subscriptions app
For Django-based SaaS projects.
Django App for You
Django GDPR Cookie Consent app
For Django websites that use cookies.
Django App for You