
--- action.py
+++ action.py
... | ... | @@ -1,14 +1,12 @@ |
1 | 1 |
|
2 | 2 |
from flask_restx import Resource, Api, Namespace, fields,reqparse |
3 | 3 |
from flask import request,jsonify |
4 |
-from flask import Flask, render_template, request |
|
5 |
-from werkzeug.utils import secure_filename |
|
4 |
+from flask import Flask, request |
|
6 | 5 |
import os |
7 | 6 |
from haversine import haversine |
8 | 7 |
from database.database import DB |
9 | 8 |
from datetime import datetime |
10 | 9 |
import pandas as pd |
11 |
-from io import StringIO |
|
12 | 10 |
import jwt |
13 | 11 |
|
14 | 12 |
|
... | ... | @@ -44,33 +42,31 @@ |
44 | 42 |
@Action.doc(responses={200: 'Success'}) |
45 | 43 |
@Action.doc(responses={500: 'Register Failed'}) |
46 | 44 |
def post(self): |
47 |
- if request.method == 'POST': |
|
48 |
- current_time = datetime.now() |
|
49 |
- timestamp = current_time.strftime("%Y%m%d%H%M%S") |
|
50 |
-# 시간을 원하는 형식으로 포맷팅하기 (예: 년-월-일 시:분:초) |
|
51 |
- formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S") |
|
52 |
- # 포맷팅된 현재 시간 출력 |
|
53 |
- token = request.headers.get('Authorization') |
|
54 |
- print(token) |
|
55 |
- #print(token) |
|
56 |
- if not token: |
|
57 |
- return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}) |
|
58 |
- |
|
59 |
- else: |
|
45 |
+ if request.method == 'POST': |
|
46 |
+ current_time = datetime.now() |
|
47 |
+ timestamp = current_time.strftime("%Y%m%d%H%M%S") |
|
48 |
+ # 시간을 원하는 형식으로 포맷팅하기 (예: 년-월-일 시:분:초) |
|
49 |
+ formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S") |
|
50 |
+ # 포맷팅된 현재 시간 출력 |
|
51 |
+ token = request.headers.get('Authorization') |
|
52 |
+ print(token) |
|
53 |
+ if not token: |
|
54 |
+ return jsonify({'result': 'fail', 'msg': '토큰이 없습니다.'}) |
|
55 |
+ else: |
|
60 | 56 |
# Decode the token to verify it |
61 |
- decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
|
62 |
- print(decoded_token) |
|
63 |
- user_id = decoded_token['id'] |
|
64 |
- print("현재 시간,저장요청:", formatted_time) |
|
65 |
- f = request.files['file'] |
|
66 |
- save_path = f"images/{timestamp}/{user_id}" |
|
67 |
- os.makedirs(save_path, exist_ok=True) |
|
68 |
- new_filename = f"{save_path}/{user_id}_{timestamp}.jpg" |
|
69 |
- print(f) |
|
70 |
- f.save(new_filename) |
|
71 |
- print("저장완료", formatted_time) |
|
57 |
+ decoded_token = jwt.decode(token, "secret", algorithms=['HS256']) |
|
58 |
+ print(decoded_token) |
|
59 |
+ user_id = decoded_token['id'] |
|
60 |
+ print("현재 시간,저장요청:", formatted_time) |
|
61 |
+ f = request.files['file'] |
|
62 |
+ save_path = f"images/{timestamp}/{user_id}" |
|
63 |
+ os.makedirs(save_path, exist_ok=True) |
|
64 |
+ new_filename = f"{save_path}/{user_id}_{timestamp}.jpg" |
|
65 |
+ print(f) |
|
66 |
+ f.save(new_filename) |
|
67 |
+ print("저장완료", formatted_time) |
|
72 | 68 |
|
73 |
- return { |
|
69 |
+ return { |
|
74 | 70 |
'save': 'done' # str으로 반환하여 return |
75 | 71 |
}, 200 |
76 | 72 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?