file upload
This commit is contained in:
+21
-16
@@ -13,7 +13,8 @@ from app.api.services import (
|
||||
SubscriptionsService,
|
||||
CommonDataService,
|
||||
OfficeCustomerService,
|
||||
GenerativesService, OfficeUsersService, OfficeTemplatesService, OfficeCountryService, WebsiteService
|
||||
GenerativesService, OfficeUsersService, OfficeTemplatesService, OfficeCountryService, WebsiteService,
|
||||
FileUploadService
|
||||
)
|
||||
from app.api.services.comments import CommentsService
|
||||
from app.models import Country
|
||||
@@ -120,6 +121,8 @@ def allowed_file(filename):
|
||||
|
||||
@api.route('/upload/webfiles', methods=['GET', 'POST'])
|
||||
def upload_file():
|
||||
response = []
|
||||
|
||||
if request.method == 'POST':
|
||||
logger.info('POST CALLED 0')
|
||||
logger.info(f'POST CALLED 1 {request}')
|
||||
@@ -127,10 +130,10 @@ def upload_file():
|
||||
logger.info(f'POST CALLED 3 {request.files}')
|
||||
|
||||
member_uid = request.form.get('member_uid' '')
|
||||
member_id = request.form.get('member_id', '0') # Use .get() to avoid errors if key is missing
|
||||
token = request.form.get('token', '') # Use .get() to avoid errors if key is missing
|
||||
|
||||
logger.info(f'POST CALLED 22 {member_uid}')
|
||||
logger.info(f'POST CALLED 33 {member_id}')
|
||||
logger.info(f'POST CALLED 33 {token}')
|
||||
|
||||
# check if the post request has the file part
|
||||
if 'file' not in request.files:
|
||||
@@ -146,24 +149,26 @@ def upload_file():
|
||||
|
||||
if file and allowed_file(file.filename):
|
||||
logger.info(f'POST CALLED 5 {file.filename}')
|
||||
save_path=UPLOAD_FOLDER + "/" + "F000000000001"
|
||||
filename = secure_filename(file.filename)
|
||||
final_save_path = os.path.join(save_path, filename)
|
||||
logger.info(f'POST CALLED 6 {final_save_path}')
|
||||
response = FileUploadService.process_file_upload("WEB_MEDIA", file ,member_uid )
|
||||
|
||||
try:
|
||||
if not os.path.isdir(save_path):
|
||||
os.makedirs(save_path)
|
||||
|
||||
file.save(final_save_path)
|
||||
except Exception as e:
|
||||
# Catches any other exception and stores the message in 'e'
|
||||
print(f"An unexpected error occurred: {e}")
|
||||
# save_path=UPLOAD_FOLDER + "/" + "F000000000001"
|
||||
# filename = secure_filename(file.filename)
|
||||
# final_save_path = os.path.join(save_path, filename)
|
||||
# logger.info(f'POST CALLED 6 {final_save_path}')
|
||||
#
|
||||
# try:
|
||||
# if not os.path.isdir(save_path):
|
||||
# os.makedirs(save_path)
|
||||
#
|
||||
# file.save(final_save_path)
|
||||
# except Exception as e:
|
||||
# # Catches any other exception and stores the message in 'e'
|
||||
# print(f"An unexpected error occurred: {e}")
|
||||
|
||||
if request.method == 'GET':
|
||||
logger.info('GET CALLED')
|
||||
|
||||
return []
|
||||
return response
|
||||
|
||||
|
||||
@api.route("/panel/account", methods=["POST"])
|
||||
|
||||
Reference in New Issue
Block a user