INNER CODE UNIT · Python
download_image
openfoodfacts/openfoodfacts-ai · category-detection/main.py:264
async def download_image(url: str, session: aiohttp.ClientSession) -> bytes:
"""Download an image from a URL and return its content as bytes.
Args:
url (str): URL of the image to download.
Returns:
bytes: Content of the downloaded image.
"""
async with session.get(url) as response:
response.raise_for_status()
return await response.read()
async def download_image_from_filesystem(url: str, base_dir: Path) -> bytes:
"""Download an image from the filesystem and return its content as bytes.
Args:
url (str): URL of the image to download.