Closed Lepiloff closed 4 years ago
Hi! I am trying to use asynchronous file deletion with aiofiles.os.remove but the file is not deleted from the disk. Code sample
async def create_upload_file(file: UploadFile = File(...)): _, ext = os.path.splitext(file.filename) content = await file.read() if file.content_type not in ['image/jpeg', 'image/png']: raise HTTPException(status_code=406, detail="Only .jpeg or .png files allowed") file_name = f'{uuid.uuid4().hex}{ext}' async with aiofiles.open(file_name, "wb") as f: await f.write(content) path_to_img = os.path.abspath(file_name) try: response = detect_text(path_to_img) finally: aiofiles.os.remove(path_to_img) return {"file_info": response}
If I change aiofiles.os.remove(path_to_img) to os.remove(path_to_img) its work as expected. What's the reason?
aiofiles.os.remove(path_to_img)
I forgot to insert await before calling aiofiles.os.remove().
Hi! I am trying to use asynchronous file deletion with aiofiles.os.remove but the file is not deleted from the disk. Code sample
If I change
aiofiles.os.remove(path_to_img)
to os.remove(path_to_img) its work as expected. What's the reason?