import os
import tempfile

# response
# return StreamingResponse(image_data, media_type="image/png")

with tempfile.NamedTemporaryFile("wb", delete=False) as f:
    f.write(response.content)
    print(f"새로운 파일: {f.__dict__}")
		"""{
			'file': <_io.BufferedWriter name='C:\\Users\\temp\\AppData\\Local\\Temp\\tmprk5y2mf6'>, 
			'name': 'C:\\Users\\temp\\AppData\\Local\\Temp\\tmprk5y2mf6', 
			'delete': False, 
			'_closer': <tempfile._TemporaryFileCloser object at 0x00000199A04B6610>, 
			'write': <function BufferedWriter.write at 0x00000199A0756980>
		}
		"""
    from uuid import uuid4
		
    file_name = uuid4()
    file_path = f"my/bucket/adderss/img_{file_name}.png"
    # 업로드_함수에서 temp 파일 경로인 f.name open(임시파일경로, 'rb')로 읽어 처리한다.
    image_url = await 업로드_함수(f.name, file_path)

os.remove(f.name)

+ Recent posts