mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: add document pdf activity type
This commit is contained in:
parent
be57196fb7
commit
9dbd47c36f
9 changed files with 263 additions and 8 deletions
23
src/services/courses/activities/uploads/pdfs.py
Normal file
23
src/services/courses/activities/uploads/pdfs.py
Normal 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue