Skip to content

Commit

Permalink
feat : s3에 사진 보내기에서 다운로드로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Mar 23, 2024
1 parent eb706dd commit f276d50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,6 @@ jobs:
target: "/home/ubuntu/server-flask"
port: 22

- name: SCP image file to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
source: "dd.jpeg"
target: "/home/ubuntu/server-flask"
port: 22


- name: SCP .env file to EC2
uses: appleboy/scp-action@master
with:
Expand Down
17 changes: 9 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import (Flask, jsonify)
from flask import (Flask, jsonify, send_file)
from dotenv import load_dotenv
import boto3
# from connection import s3_connection
Expand All @@ -24,7 +24,7 @@ def test2(): # put application's code here
return 'post test2'


@app.route('/image', methods=['POST'])
@app.route('/image', methods=['GET'])
def test_image():
try:
client = boto3.client('s3',
Expand All @@ -33,14 +33,15 @@ def test_image():
region_name=os.getenv('REGION_NAME')
)

file_name = 'dd.jpeg' # 업로드할 파일 이름
if not os.path.exists(file_name):
return jsonify({'error': "파일이 존재하지 않습니다."}), 400
file_name = 'download.jpeg' # 업로드할 파일 이름
# if not os.path.exists(file_name):
# return jsonify({'error': "파일이 존재하지 않습니다."}), 400
bucket = os.getenv('BUCKET_NAME') # 버켓 주소
key = 'dd.jpeg' # s3 파일 이미지
key = '디코 토끼.jpeg' # s3 파일 이미지

client.upload_file(file_name, bucket, key) # 파일 저장
return jsonify({'success': True})
client.download_file(bucket, key,file_name) # 파일 저장
return send_file(file_name, as_attachment=True, attachment_filename=key)
# return jsonify({'success': True})

except TypeError as e:
# TypeError 발생 시, 오류 로깅
Expand Down

0 comments on commit f276d50

Please sign in to comment.