From 193413025453697648268370b108eb68caba972b Mon Sep 17 00:00:00 2001 From: sycuuui <102959791+sycuuui@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:06:31 +0900 Subject: [PATCH] =?UTF-8?q?fix=20:=20=EC=8B=A4=ED=96=89=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95,=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/github-actions.yml | 2 +- app.py | 32 ++++++++++++++-------------- connection.py | 18 ++++++++-------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 547fe8e..676d7e9 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -41,7 +41,7 @@ jobs: run: | # 프로젝트 실행 명령어 또는 스크립트를 실행 # 예를 들어, Flask 앱 실행: - python app.py # 이 부분을 프로젝트 실행하는 명령어 또는 스크립트로 대체해야 함 + #python app.py # 이 부분을 프로젝트 실행하는 명령어 또는 스크립트로 대체해야 함 # Docker 빌드 & 푸시 - name: Docker build & push diff --git a/app.py b/app.py index e56a5e3..d82d414 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,6 @@ from flask import (Flask, jsonify) -# from connection import s3_connection -# import os +from connection import s3_connection +import os app = Flask(__name__) @@ -22,20 +22,20 @@ def test2(): # put application's code here def test3(): # put application's code here return 'post test3' -# @app.route('/image', methods=['POST']) -# def test_image(): -# s3 = s3_connection() -# try: -# with open('dd.jpeg', 'rb') as image_file: -# s3.put_object( -# Bucket=os.getenv('BUCKET_NAME'), -# Body=image_file, -# Key='dd.jpeg', -# ContentType='image/jpeg' -# ) -# return jsonify({'success': True}) -# except Exception as e: -# return jsonify({'error': str(e)}) +@app.route('/image', methods=['POST']) +def test_image(): + s3 = s3_connection() + try: + with open('dd.jpeg', 'rb') as image_file: + s3.put_object( + Bucket=os.getenv('BUCKET_NAME'), + Body=image_file, + Key='dd.jpeg', + ContentType='image/jpeg' + ) + return jsonify({'success': True}) + except Exception as e: + return jsonify({'error': str(e)}) if __name__ == '__main__': app.run(host='0.0.0.0', port='5000') diff --git a/connection.py b/connection.py index e6bb7c6..5d57ba5 100644 --- a/connection.py +++ b/connection.py @@ -1,9 +1,9 @@ -# import boto3 -# import os -# -# -# def s3_connection(): -# s3 = boto3.client('s3', -# aws_access_key_id=os.getenv('AWS_ACCESS_KEY'), -# aws_secret_access_key=os.getenv('AWS_SECRET_KEY')) -# return s3 +import boto3 +import os + + +def s3_connection(): + s3 = boto3.client('s3', + aws_access_key_id=os.getenv('AWS_ACCESS_KEY'), + aws_secret_access_key=os.getenv('AWS_SECRET_KEY')) + return s3