Loading File_Upload.ipynb 0 → 100644 +91 −0 Original line number Diff line number Diff line %% Cell type:code id:18579ed8-a64a-4cbf-9c09-8050517581fc tags: ``` python from flask import Flask, render_template, request from flask_cors import CORS from werkzeug.utils import secure_filename import os app = Flask(__name__) CORS(app) # https://api-test.biblio19.net UPLOAD_FOLDER1 = '/home/s60181908/tmp1' # 업로드 파일을 저장할 디렉토리 설정 111 UPLOAD_FOLDER2 = '/home/s60181908/tmp2' # 업로드 파일을 저장할 디렉토리 설정 222 app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER1 def is_json_file(filename): return filename.lower().endswith(".json") @app.route('/', methods=['GET']) def index(): return 'Hello World!' @app.route('/upload_path1', methods=['POST']) def upload_file1(): if request.method == 'POST': files = request.files.getlist('file') # 'file'라는 필드에서 파일 리스트 가져옴 for file in files: if file: filename = secure_filename(file.filename) if not is_json_file(filename): abort(400, "파일은 JSON 형식이어야 합니다.") file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return "Files uploaded successfully" return ''' <!doctype html> <title>File Upload</title> <h1>Upload Files</h1> <form method=post enctype=multipart/form-data> <input type=file name=file multiple> <input type=submit value=Upload> </form> ''' @app.route('/upload_path2', methods=['POST']) def upload_file2(): if request.method == 'POST': files = request.files.getlist('file') # 'file'라는 필드에서 파일 리스트 가져옴 for file in files: if file: filename = secure_filename(file.filename) if not is_json_file(filename): abort(400, "파일은 JSON 형식이어야 합니다.") file.save(os.path.join(UPLOAD_FOLDER2, filename)) return "Files uploaded successfully" return ''' <!doctype html> <title>File Upload</title> <h1>Upload Files</h1> <form method=post enctype=multipart/form-data> <input type=file name=file multiple> <input type=submit value=Upload> </form> ''' if __name__ == '__main__': app.run(host='0.0.0.0') ``` %% Output * Serving Flask app '__main__' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5000 * Running on http://192.168.32.2:5000 Press CTRL+C to quit 192.168.32.1 - - [22/Oct/2023 09:07:12] "POST /upload_path1 HTTP/1.1" 200 - 192.168.32.1 - - [22/Oct/2023 09:07:17] "POST /upload_path2 HTTP/1.1" 200 - %% Cell type:code id:2f8d905f-4429-4107-9392-b1e7695df498 tags: ``` python ``` Loading
File_Upload.ipynb 0 → 100644 +91 −0 Original line number Diff line number Diff line %% Cell type:code id:18579ed8-a64a-4cbf-9c09-8050517581fc tags: ``` python from flask import Flask, render_template, request from flask_cors import CORS from werkzeug.utils import secure_filename import os app = Flask(__name__) CORS(app) # https://api-test.biblio19.net UPLOAD_FOLDER1 = '/home/s60181908/tmp1' # 업로드 파일을 저장할 디렉토리 설정 111 UPLOAD_FOLDER2 = '/home/s60181908/tmp2' # 업로드 파일을 저장할 디렉토리 설정 222 app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER1 def is_json_file(filename): return filename.lower().endswith(".json") @app.route('/', methods=['GET']) def index(): return 'Hello World!' @app.route('/upload_path1', methods=['POST']) def upload_file1(): if request.method == 'POST': files = request.files.getlist('file') # 'file'라는 필드에서 파일 리스트 가져옴 for file in files: if file: filename = secure_filename(file.filename) if not is_json_file(filename): abort(400, "파일은 JSON 형식이어야 합니다.") file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return "Files uploaded successfully" return ''' <!doctype html> <title>File Upload</title> <h1>Upload Files</h1> <form method=post enctype=multipart/form-data> <input type=file name=file multiple> <input type=submit value=Upload> </form> ''' @app.route('/upload_path2', methods=['POST']) def upload_file2(): if request.method == 'POST': files = request.files.getlist('file') # 'file'라는 필드에서 파일 리스트 가져옴 for file in files: if file: filename = secure_filename(file.filename) if not is_json_file(filename): abort(400, "파일은 JSON 형식이어야 합니다.") file.save(os.path.join(UPLOAD_FOLDER2, filename)) return "Files uploaded successfully" return ''' <!doctype html> <title>File Upload</title> <h1>Upload Files</h1> <form method=post enctype=multipart/form-data> <input type=file name=file multiple> <input type=submit value=Upload> </form> ''' if __name__ == '__main__': app.run(host='0.0.0.0') ``` %% Output * Serving Flask app '__main__' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5000 * Running on http://192.168.32.2:5000 Press CTRL+C to quit 192.168.32.1 - - [22/Oct/2023 09:07:12] "POST /upload_path1 HTTP/1.1" 200 - 192.168.32.1 - - [22/Oct/2023 09:07:17] "POST /upload_path2 HTTP/1.1" 200 - %% Cell type:code id:2f8d905f-4429-4107-9392-b1e7695df498 tags: ``` python ```