Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created February 14, 2025 01:36
Show Gist options
  • Select an option

  • Save KyMidd/e466ee540b161e138d1522ae726843c1 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/e466ee540b161e138d1522ae726843c1 to your computer and use it in GitHub Desktop.
# Check the mime type of the file is a supported image file type
if file["mimetype"] in [
"image/png", # png
"image/jpeg", # jpeg
"image/gif", # gif
"image/webp", # webp
]:
# Isolate the file type based on the mimetype
file_type = file["mimetype"].split("/")[1]
# Append the file to the content array
content.append(
{
"image": {
"format": file_type,
"source": {
"bytes": file_content,
}
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment