from typing import List from PIL import Image from fastapi import FastAPI, File, UploadFile from fastapi.responses import FileResponse import shutil from werkzeug.utils import secure_filename app = FastAPI() async def get_image(file): filename = secure_filename(file.filename) with open(filename,"wb") as buffer: shutil.copyfileobj(file.file, buffer) return filename @app.post("/uploadfiles/") async def upload_images(file: List[UploadFile] = File(...),): with open(f'{file.filename}',"wb") as buffer: shutil.copyfileobj(file.file,buffer) return FileResponse (file.filename) @app.post("/grey_image/") async def create_grey_img(file:list[UploadFile]): filename= await get_image(file) img = Image.open(filename) img.convert('L').save('grey_img.jpg') return FileResponse("grey_img.jpg")
filename
file
List
Quote:async def upload_images(file: List[UploadFile] = File(...),):
Quote:async def create_grey_img(file:list[UploadFile]):
for single_file in file: # do stuff here
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)