Skip to content

Commit

Permalink
Chore : #24 Add library 'requests'
Browse files Browse the repository at this point in the history
  • Loading branch information
gilyeon00 committed Sep 23, 2022
1 parent f8d91d3 commit 38086ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ amqp
flask_jwt_extended
flask_bcrypt
flask_restx
redis
redis
requests
21 changes: 13 additions & 8 deletions service/image_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from entity.model import Image
from entity import database

import requests
from datetime import datetime as dt
from s3bucket.s3_connect import s3
from s3bucket.s3_upload import s3_put_result_image, s3_put_origin_image
Expand All @@ -28,23 +29,27 @@ def saveOriginImage(file, email) :

# 파일 이름 지정
filename = file.filename.split('.')[0]
image_type = file.filename.split('.')[-1]
image_created = dt.now().strftime('%Y-%m-%d-%H-%M-%S')
image_name = f"{image_created}--{filename}.{image_type}"
origin_image_type = file.filename.split('.')[-1]
origin_image_created = dt.now().strftime('%Y-%m-%d-%H-%M-%S')
origin_image_name = f"{origin_image_created}--{filename}.{origin_image_type}"

# s3버킷에 업로드
s3_put_result_image(s3, 'ladder-s3-bucket', file, image_name)
s3_put_result_image(s3, 'ladder-s3-bucket', file, origin_image_name)

# postgres image table에 origin_url 업로드
origin_url = "https://ladder-s3-bucket.s3.ap-northeast-2.amazonaws.com/origin/"+image_name
origin_url = "https://ladder-s3-bucket.s3.ap-northeast-2.amazonaws.com/origin/"+origin_image_name
origin_url = origin_url.replace(" ","/")
database.add_instance(Image, user_id = user_id, origin_url = origin_url, is_deleted = False)

print("성공적으로 사진이 S3에 저장되었습니다.")

# ai 셀러리 요청, 이제 요 다음부터 비동기처리
convertImage.delay(origin_url)


# celery가 처리할 거
# api요청 (ai 서버)


# upload s3 .. (이건 만들어진 api로 보내도 됨 아니면 그냥 여기에 함수 쓰기)
@app.task()
def convertImage(origin_url):
result_image = requests.post('''api이름''', origin_url)
# upload ( result_image )

0 comments on commit 38086ee

Please sign in to comment.