Skip to content

Commit

Permalink
feat : s3이용한 image upload
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Mar 21, 2024
1 parent 22b7e5c commit 18c992d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.11.6'

- name: Set Environment Variables
run: |
echo "BUCKET_NAME=${{ secrets.BUCKET_NAME }}" >> $GITHUB_ENV
echo "AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY }}" >> $GITHUB_ENV
echo "AWS_SECRET_KEY=${{ secrets.AWS_SECRET_KEY }}" >> $GITHUB_ENV
19 changes: 18 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from flask import Flask
from flask import (Flask, jsonify)
from connection import s3_connection
import os

app = Flask(__name__)

Expand All @@ -20,5 +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)})

if __name__ == '__main__':
app.run(host='0.0.0.0', port='5000')
7 changes: 3 additions & 4 deletions connection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import boto3

from config import AWS_ACCESS_KEY, AWS_SECRET_KEY
import os


def s3_connection():
s3 = boto3.client('s3',
aws_access_key_id=AWS_ACCESS_KEY,
aws_secret_access_key=AWS_SECRET_KEY)
aws_access_key_id=os.getenv('AWS_ACCESS_KEY'),
aws_secret_access_key=os.getenv('AWS_SECRET_KEY'))
return s3

0 comments on commit 18c992d

Please sign in to comment.