24 lines
		
	
	
		
			629 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			24 lines
		
	
	
		
			629 B
		
	
	
	
		
			Python
		
	
	
	
	
	
import asyncio
 | 
						|
import base64
 | 
						|
from typing import List, Tuple, Optional
 | 
						|
 | 
						|
import aiohttp
 | 
						|
 | 
						|
 | 
						|
async def fetch_image(url: Optional[str]) -> str:
 | 
						|
    if not url:
 | 
						|
        return ""
 | 
						|
 | 
						|
    async with aiohttp.ClientSession() as session:
 | 
						|
        async with session.get(url) as response:
 | 
						|
            if response.status == 200:
 | 
						|
                image_data = await response.read()
 | 
						|
                return base64.b64encode(image_data).decode("utf-8")
 | 
						|
            else:
 | 
						|
                return ""
 | 
						|
 | 
						|
 | 
						|
async def fetch_images(urls: List[Optional[str]]) -> Tuple[str]:
 | 
						|
    tasks = [fetch_image(url) for url in urls]
 | 
						|
    return await asyncio.gather(*tasks)
 |