CREATE: static file + upload image
This commit is contained in:
@@ -437,33 +437,33 @@ async def score_all_post(
|
||||
return posts
|
||||
|
||||
|
||||
@post.post("/uploadfiles/")
|
||||
async def create_upload_files(
|
||||
files: List[UploadFile] = File(...),
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
):
|
||||
try:
|
||||
file_name = []
|
||||
i = 0
|
||||
file_location = f"../media/"
|
||||
for file in files:
|
||||
current_time = datetime.datetime.now(tz=tz)
|
||||
file_save = file_location + current_time + str(i) + file.filename
|
||||
file_name.append(current_time + str(i) + file.filename)
|
||||
i = i + 1
|
||||
with open(file_save, "wb+") as file_object:
|
||||
file_object.write(file.file.read())
|
||||
return {"filenames": file_name}
|
||||
except Exception as e:
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
content={'message': str(e)}
|
||||
)
|
||||
# @post.post("/uploadfiles/")
|
||||
# async def create_upload_files(
|
||||
# files: List[UploadFile] = File(...),
|
||||
# # current_user: UserModel = Depends(get_current_user)
|
||||
# ):
|
||||
# try:
|
||||
# file_name = []
|
||||
# i = 0
|
||||
# file_location = f"../media/"
|
||||
# for file in files:
|
||||
# current_time = datetime.datetime.now(tz=tz)
|
||||
# file_save = file_location + current_time + str(i) + file.filename
|
||||
# file_name.append(current_time + str(i) + file.filename)
|
||||
# i = i + 1
|
||||
# with open(file_save, "wb+") as file_object:
|
||||
# file_object.write(file.file.read())
|
||||
# return {"filenames": file_name}
|
||||
# except Exception as e:
|
||||
# return JSONResponse(
|
||||
# status_code=status.HTTP_400_BAD_REQUEST,
|
||||
# content={'message': str(e)}
|
||||
# )
|
||||
|
||||
|
||||
@post.post("/upload_post/")
|
||||
@post.post("/upload_file/")
|
||||
async def create_upload_post(
|
||||
post: List[UploadFile] = File(...),
|
||||
# post: List[UploadFile] = File(...),
|
||||
image: List[UploadFile] = File(...),
|
||||
# current_user: UserModel = Depends(get_current_user)
|
||||
):
|
||||
@@ -471,22 +471,22 @@ async def create_upload_post(
|
||||
|
||||
file_name = []
|
||||
i = 0
|
||||
now = datetime.datetime.now(tz=tz)
|
||||
current_time = now.strftime("%H_%M_%S_%d-%m-%Y_")
|
||||
folder_save = f"./post/" + current_time + str(i)
|
||||
Path(folder_save).mkdir(parents=True)
|
||||
for file in post:
|
||||
file_save = folder_save + "/" + file.filename
|
||||
file_name.append(current_time + str(i) + "/" + file.filename)
|
||||
i = i + 1
|
||||
with open(file_save, "wb+") as file_object:
|
||||
file_object.write(file.file.read())
|
||||
# now = datetime.datetime.now(tz=tz)
|
||||
# current_time = now.strftime("%H_%M_%S_%d-%m-%Y_")
|
||||
folder_save = f"./post/"
|
||||
# Path(folder_save).mkdir(parents=True)
|
||||
# for file in post:
|
||||
# file_save = folder_save + "/" + file.filename
|
||||
# file_name.append(current_time + str(i) + "/" + file.filename)
|
||||
# i = i + 1
|
||||
# with open(file_save, "wb+") as file_object:
|
||||
# file_object.write(file.file.read())
|
||||
|
||||
folder_save = folder_save + "/images"
|
||||
Path(folder_save).mkdir(parents=True, exist_ok=True)
|
||||
for file in image:
|
||||
file_save = folder_save + "/" + file.filename
|
||||
i = i + 1
|
||||
file_name.append(file_save)
|
||||
with open(file_save, "wb+") as file_object:
|
||||
file_object.write(file.file.read())
|
||||
return {"filenames": file_name}
|
||||
@@ -511,34 +511,34 @@ async def create_upload_post(
|
||||
# )
|
||||
|
||||
|
||||
@post.get("/showfile/{name}")
|
||||
async def show_file(name: str
|
||||
# , current_user: UserModel = Depends(get_current_user)
|
||||
):
|
||||
file_path = f"../media/" + name
|
||||
if os.path.exists(file_path):
|
||||
return FileResponse(file_path)
|
||||
return {"erro": "File not found!"}
|
||||
# @post.get("/showfile/{name}")
|
||||
# async def show_file(name: str
|
||||
# # , current_user: UserModel = Depends(get_current_user)
|
||||
# ):
|
||||
# file_path = f"../media/" + name
|
||||
# if os.path.exists(file_path):
|
||||
# return FileResponse(file_path)
|
||||
# return {"erro": "File not found!"}
|
||||
|
||||
|
||||
@post.get("/showvideo/{file_name}", response_class=FileResponse)
|
||||
async def main(file_name: str
|
||||
# , current_user: UserModel = Depends(get_current_user)
|
||||
):
|
||||
file_path = f"../media/" + file_name
|
||||
return file_path
|
||||
# @post.get("/showvideo/{file_name}", response_class=FileResponse)
|
||||
# async def main(file_name: str
|
||||
# # , current_user: UserModel = Depends(get_current_user)
|
||||
# ):
|
||||
# file_path = f"../media/" + file_name
|
||||
# return file_path
|
||||
|
||||
|
||||
@post.get("/video")
|
||||
async def video_endpoint(video_name
|
||||
# , current_user: UserModel = Depends(get_current_user)
|
||||
):
|
||||
def iterfile():
|
||||
video_path = f"../media/" + video_name
|
||||
with open(video_path, mode="rb") as file_like:
|
||||
yield from file_like
|
||||
# @post.get("/video")
|
||||
# async def video_endpoint(video_name
|
||||
# # , current_user: UserModel = Depends(get_current_user)
|
||||
# ):
|
||||
# def iterfile():
|
||||
# video_path = f"../media/" + video_name
|
||||
# with open(video_path, mode="rb") as file_like:
|
||||
# yield from file_like
|
||||
|
||||
return StreamingResponse(iterfile(), media_type="video/mp4")
|
||||
# return StreamingResponse(iterfile(), media_type="video/mp4")
|
||||
|
||||
|
||||
@post.post("/edit_post/{id}", response_description="score all post")
|
||||
|
||||
Reference in New Issue
Block a user