Skip to content

Commit

Permalink
add basic file saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferrariic committed Nov 26, 2022
1 parent 66979ec commit acf3c95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions api/routers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import List, Optional
from pymysql import Timestamp
import datetime
import os

from api.database.functions import hashbrown, sqlalchemy_result
from api.database.models import Registration, Tokens
Expand All @@ -14,6 +15,7 @@
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.sql.expression import select, update
from fastapi import File, UploadFile

router = APIRouter()

Expand All @@ -24,8 +26,20 @@ async def get_profile_information(token: str) -> json:


@router.post("/v1/profiles/{token}", tags=["profile"])
async def post_profile_picture(token: str) -> json:
"""returns profile picture string, and user id"""
async def post_profile_picture(token: str, file: UploadFile = File(...)) -> json:
# get user id from token

try:
contents = file.file.read()
os.mkdir(f"./images/{token}")
with open(f"./images/{token}/{file.filename}", "wb") as f:
f.write(contents)
except Exception:
return {"message": "File could not be uploaded. Try again later!"}
finally:
file.file.close()

return {"message": f"Successfully uploaded {file.filename}"}


@router.get("/v1/profile-details/{token}/{user_id}", tags=["profile"])
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ services:
env_file:
- .env
volumes:
- ../../API_volume:/code/images:rw
- /home/ubuntu/images:/code/images:rw

0 comments on commit acf3c95

Please sign in to comment.