Добавил новые эндпоинты для загрузки
This commit is contained in:
parent
637f0401da
commit
78d7b3a412
3 changed files with 32 additions and 4 deletions
7
.dockerignore
Normal file
7
.dockerignore
Normal file
|
@ -0,0 +1,7 @@
|
|||
.venv
|
||||
.idea
|
||||
.gitignore
|
||||
bp/
|
||||
app/static/images/images/
|
||||
app/static/images/backgrounds/
|
||||
app/static/images/avatars/
|
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -162,3 +162,9 @@ cython_debug/
|
|||
|
||||
node_modules
|
||||
.env_non_dev
|
||||
|
||||
bp/
|
||||
|
||||
app/static/images/images/
|
||||
app/static/images/backgrounds/
|
||||
app/static/images/avatars/
|
||||
|
|
21
app/main.py
21
app/main.py
|
@ -37,14 +37,29 @@ app.add_middleware(
|
|||
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
||||
|
||||
|
||||
@app.post('/images', response_model=dict[str, str])
|
||||
async def upload_images(file: UploadFile):
|
||||
@app.post('/upload_avatar', response_model=dict[str, str])
|
||||
async def upload_avatar(file: UploadFile):
|
||||
name = generate_random_string()
|
||||
image_url = f'static/images/{name}_avatar.png'
|
||||
image_url = f'static/images/avatars/{name}_avatar.png'
|
||||
with open('app/' + image_url, 'wb+') as file_object:
|
||||
shutil.copyfileobj(file.file, file_object)
|
||||
return {'image_url': image_url}
|
||||
|
||||
|
||||
@app.post('/upload_background', response_model=dict[str, str])
|
||||
async def upload_background(file: UploadFile):
|
||||
name = file.filename.split('.')[0]
|
||||
file_format = file.filename.split('.')[-1]
|
||||
image_url = f'static/images/backgrounds/{name}_background.{file_format}'
|
||||
with open('app/' + image_url, 'wb+') as file_object:
|
||||
shutil.copyfileobj(file.file, file_object)
|
||||
return {'image_url': image_url}
|
||||
|
||||
|
||||
@app.post('/upload_image', response_model=dict[str, str])
|
||||
async def upload_image(file: UploadFile):
|
||||
name = generate_random_string(50)
|
||||
image_url = f'static/images/images/{name}_image.png'
|
||||
with open('app/' + image_url, 'wb+') as file_object:
|
||||
shutil.copyfileobj(file.file, file_object)
|
||||
return {'image_url': image_url}
|
||||
|
|
Loading…
Add table
Reference in a new issue