Я бы хотел, чтобы все операции записи файлов происходили во временном каталоге, поэтому он очищается.
Маршрут работает нормально, если выходной файл нет во временном каталоге. Но если я попытаюсь поместить выходной файл во временный каталог, FileResponse не сможет его найти, и запросы не будут выполнены.
Код: Выделить всё
RuntimeError: File at path /tmp/tmpp5x_p4n9/out.jpg does not exist.Код: Выделить всё
@app.post("/heic")
async def heic(img: UploadFile):
with TemporaryDirectory() as dir:
inname = os.path.join(dir, "img.heic")
f = open(inname,"wb")
f.write(img.file.read())
f.flush()
# setting outname in the temp dir fails!
# outname = os.path.join(dir, 'out.jpg')
outname = os.path.join('out.jpg')
cmd = f"oiiotool {f.name} -o {outname}"
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
process.wait()
return FileResponse(outname, headers={'Content-Disposition':'attachment; filename=response.csv'})
Подробнее здесь: https://stackoverflow.com/questions/725 ... pdirectory
Мобильная версия