file upload
This commit is contained in:
+21
-16
@@ -13,7 +13,8 @@ from app.api.services import (
|
|||||||
SubscriptionsService,
|
SubscriptionsService,
|
||||||
CommonDataService,
|
CommonDataService,
|
||||||
OfficeCustomerService,
|
OfficeCustomerService,
|
||||||
GenerativesService, OfficeUsersService, OfficeTemplatesService, OfficeCountryService, WebsiteService
|
GenerativesService, OfficeUsersService, OfficeTemplatesService, OfficeCountryService, WebsiteService,
|
||||||
|
FileUploadService
|
||||||
)
|
)
|
||||||
from app.api.services.comments import CommentsService
|
from app.api.services.comments import CommentsService
|
||||||
from app.models import Country
|
from app.models import Country
|
||||||
@@ -120,6 +121,8 @@ def allowed_file(filename):
|
|||||||
|
|
||||||
@api.route('/upload/webfiles', methods=['GET', 'POST'])
|
@api.route('/upload/webfiles', methods=['GET', 'POST'])
|
||||||
def upload_file():
|
def upload_file():
|
||||||
|
response = []
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
logger.info('POST CALLED 0')
|
logger.info('POST CALLED 0')
|
||||||
logger.info(f'POST CALLED 1 {request}')
|
logger.info(f'POST CALLED 1 {request}')
|
||||||
@@ -127,10 +130,10 @@ def upload_file():
|
|||||||
logger.info(f'POST CALLED 3 {request.files}')
|
logger.info(f'POST CALLED 3 {request.files}')
|
||||||
|
|
||||||
member_uid = request.form.get('member_uid' '')
|
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 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
|
# check if the post request has the file part
|
||||||
if 'file' not in request.files:
|
if 'file' not in request.files:
|
||||||
@@ -146,24 +149,26 @@ def upload_file():
|
|||||||
|
|
||||||
if file and allowed_file(file.filename):
|
if file and allowed_file(file.filename):
|
||||||
logger.info(f'POST CALLED 5 {file.filename}')
|
logger.info(f'POST CALLED 5 {file.filename}')
|
||||||
save_path=UPLOAD_FOLDER + "/" + "F000000000001"
|
response = FileUploadService.process_file_upload("WEB_MEDIA", file ,member_uid )
|
||||||
filename = secure_filename(file.filename)
|
|
||||||
final_save_path = os.path.join(save_path, filename)
|
|
||||||
logger.info(f'POST CALLED 6 {final_save_path}')
|
|
||||||
|
|
||||||
try:
|
# save_path=UPLOAD_FOLDER + "/" + "F000000000001"
|
||||||
if not os.path.isdir(save_path):
|
# filename = secure_filename(file.filename)
|
||||||
os.makedirs(save_path)
|
# final_save_path = os.path.join(save_path, filename)
|
||||||
|
# logger.info(f'POST CALLED 6 {final_save_path}')
|
||||||
file.save(final_save_path)
|
#
|
||||||
except Exception as e:
|
# try:
|
||||||
# Catches any other exception and stores the message in 'e'
|
# if not os.path.isdir(save_path):
|
||||||
print(f"An unexpected error occurred: {e}")
|
# 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':
|
if request.method == 'GET':
|
||||||
logger.info('GET CALLED')
|
logger.info('GET CALLED')
|
||||||
|
|
||||||
return []
|
return response
|
||||||
|
|
||||||
|
|
||||||
@api.route("/panel/account", methods=["POST"])
|
@api.route("/panel/account", methods=["POST"])
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ from app.api.services.subscriptions import SubscriptionsService
|
|||||||
from app.api.services.common_data import CommonDataService
|
from app.api.services.common_data import CommonDataService
|
||||||
from app.api.services.genaratives import GenerativesService
|
from app.api.services.genaratives import GenerativesService
|
||||||
from app.api.services.comments import CommentsService
|
from app.api.services.comments import CommentsService
|
||||||
|
from app.api.services.file_upload import FileUploadService
|
||||||
|
|
||||||
|
|
||||||
#WEBSITE
|
#WEBSITE
|
||||||
from app.api.services.website import WebsiteService
|
from app.api.services.website import WebsiteService
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
from flask import jsonify
|
||||||
|
|
||||||
|
from app.api.enums import KafkaMessage
|
||||||
|
from app.api.services import MyProductsService
|
||||||
|
from app.utils.logger import logger
|
||||||
|
from app.api.services.base_service import BaseService
|
||||||
|
from sqlalchemy import func, desc
|
||||||
|
from app.extensions import db
|
||||||
|
import os
|
||||||
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
|
|
||||||
|
class FileUploadService(BaseService):
|
||||||
|
UPLOAD_FOLDER = '/app/uploads' # '/uploads'
|
||||||
|
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def process_file_upload(upload_type: str, file, member_uid):
|
||||||
|
|
||||||
|
file_uid = "I GOT HERE "
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
logger.info(f'POST CALLED 5 {file.filename}')
|
||||||
|
save_path = FileUploadService.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}')
|
||||||
|
|
||||||
|
if not os.path.isdir(save_path):
|
||||||
|
os.makedirs(save_path)
|
||||||
|
|
||||||
|
file.save(final_save_path)
|
||||||
|
|
||||||
|
response_data = {
|
||||||
|
"file_uid": file_uid,
|
||||||
|
}
|
||||||
|
|
||||||
|
return response_data
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"An error occurred while getting dashboard data: {str(e)}", exc_info=True)
|
||||||
|
return jsonify({"message": "Internal Server Error"}), 500
|
||||||
Reference in New Issue
Block a user