質問編集履歴

1

コードの追記

2021/12/31 08:28

投稿

alpha95
alpha95

スコア10

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,93 @@
6
6
 
7
7
 
8
8
 
9
+ サーバー側のコードは下記のように書きました。
9
10
 
11
+
12
+
13
+
14
+
15
+ ``ルーティング``
16
+
17
+ ```
18
+
19
+ @router.post("/", operation_id='createTrainingVideo', status_code=HTTP_201_CREATED, tags=["training_videos"])
20
+
21
+ def create_training_video(
22
+
23
+ file: UploadFile = File(...),
24
+
25
+ title: str = Form(...),
26
+
27
+ description: str = Form(...),
28
+
29
+ settings: Settings = Depends(get_settings),
30
+
31
+ db: Session = Depends(get_db)):
32
+
33
+
34
+
35
+ training_videos.create_training_video(db=db,
36
+
37
+ upload_file = file,
38
+
39
+ title=title,
40
+
41
+ description=description,
42
+
43
+ settings=settings
44
+
45
+ )
46
+
47
+
48
+
49
+ ```
50
+
51
+
52
+
53
+ ``training_videos.py``
54
+
55
+ ```
56
+
57
+ def create_training_video(db:Session,
58
+
59
+ settings: Settings,
60
+
61
+ upload_file: UploadFile,
62
+
63
+ title: str,
64
+
65
+ description: str):
66
+
67
+
68
+
69
+ content_type = upload_file.content_type.split("/")[1]
70
+
71
+ filename = datetime.utcnow().strftime("%Y%m%d%H%M%SZ-") + title + "." + content_type
72
+
73
+ aws_helper.upload_to_aws(bucket_name_str=settings.bucket_name, file="static/uploads/training_videos/mov_hts-samp001.mp4", s3_filename=filename, settings=settings)
74
+
75
+ db_training_video = TrainingVideoModel(description = description,
76
+
77
+ title = title,
78
+
79
+ video_name = filename,
80
+
81
+ created_at = datetime.utcnow())
82
+
83
+ db.add(db_training_video)
84
+
85
+ db.commit()
86
+
87
+ return Result(result=True)
88
+
89
+
90
+
91
+ ```
92
+
93
+
94
+
95
+ ``aws_helper.py``
10
96
 
11
97
  ```
12
98
 
@@ -22,11 +108,9 @@
22
108
 
23
109
  s3_client.upload_file(file, bucket_name_str, s3_filename)
24
110
 
111
+ ```
25
112
 
26
113
 
27
-
28
-
29
- ```
30
114
 
31
115
 
32
116