aitist/app.py

24 lines
754 B
Python

from fastapi import FastAPI, File, UploadFile
import tempfile
import os
# Assuming Celery is already set up and imported correctly in the project.
from tasks import delete_temp_file # Import your Celery task here.
app = FastAPI()
@app.post("/uploadfile/")
async def upload_file(file: UploadFile = File(...)):
contents = await file.read()
# Save the file to a temporary directory
temp_dir = tempfile.gettempdir()
temp_file_path = os.path.join(temp_dir, file.filename)
with open(temp_file_path, 'wb') as f:
f.write(contents)
# Call the Celery task that deletes the file after processing.
delete_temp_file.delay(temp_file_path) # Assuming this is your Celery task name.
return {"filename": file.filename}