feat: add document pdf activity type

This commit is contained in:
swve 2023-04-26 21:43:43 +02:00
parent be57196fb7
commit 9dbd47c36f
9 changed files with 263 additions and 8 deletions

View file

@ -0,0 +1,23 @@
import os
async def upload_pdf(pdf_file, activity_id):
contents = pdf_file.file.read()
pdf_format = pdf_file.filename.split(".")[-1]
if not os.path.exists("content/uploads/documents/documentpdf"):
# create folder
os.makedirs("content/uploads/documents/documentpdf")
# create folder
os.mkdir(f"content/uploads/documents/documentpdf/{activity_id}")
try:
with open(f"content/uploads/documents/documentpdf/{activity_id}/documentpdf.{pdf_format}", 'wb') as f:
f.write(contents)
f.close()
except Exception as e:
return {"message": "There was an error uploading the file"}
finally:
pdf_file.file.close()