質問編集履歴
3
追記記載漏れ
test
CHANGED
File without changes
|
test
CHANGED
@@ -234,6 +234,8 @@
|
|
234
234
|
|
235
235
|
export const createVideo = async (data) =>{
|
236
236
|
|
237
|
+
const csrfToken = Cookies.get('csrftoken');
|
238
|
+
|
237
239
|
const res = await fetch('http://localhost:8000/video/', {
|
238
240
|
|
239
241
|
method: 'POST',
|
2
リクエスト方法追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -163,3 +163,97 @@
|
|
163
163
|
<MultiValueDict: {'video': [<TemporaryUploadedFile: iiiiiiiiiiiii.mp4 (video/mp4)>]}>
|
164
164
|
|
165
165
|
```
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
###追記
|
170
|
+
|
171
|
+
リクエストはReactでFormDataを作成し、発行しています
|
172
|
+
|
173
|
+
```React
|
174
|
+
|
175
|
+
[video.js]
|
176
|
+
|
177
|
+
...省略
|
178
|
+
|
179
|
+
const handleSubmit = (event) => {
|
180
|
+
|
181
|
+
event.preventDefault();
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
const formData = new FormData();
|
186
|
+
|
187
|
+
formData.append('video', video, video.name);
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
createVideo(formData)
|
192
|
+
|
193
|
+
.then(vr => {
|
194
|
+
|
195
|
+
console.log('hogehoge');
|
196
|
+
|
197
|
+
})
|
198
|
+
|
199
|
+
.catch(e => {
|
200
|
+
|
201
|
+
throw new Error(e);
|
202
|
+
|
203
|
+
});
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
return(
|
208
|
+
|
209
|
+
<form>
|
210
|
+
|
211
|
+
<label>
|
212
|
+
|
213
|
+
動画:
|
214
|
+
|
215
|
+
<input type="file" name="video" accept='video/*' alt="動画" onChange={ (e) => setVideo(e.target.files[0]) } />
|
216
|
+
|
217
|
+
</label>
|
218
|
+
|
219
|
+
<button onClick={ handleSubmit }>送信</button>
|
220
|
+
|
221
|
+
</form>
|
222
|
+
|
223
|
+
)
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
```
|
230
|
+
|
231
|
+
[video.js]
|
232
|
+
|
233
|
+
// 登録
|
234
|
+
|
235
|
+
export const createVideo = async (data) =>{
|
236
|
+
|
237
|
+
const res = await fetch('http://localhost:8000/video/', {
|
238
|
+
|
239
|
+
method: 'POST',
|
240
|
+
|
241
|
+
headers: {
|
242
|
+
|
243
|
+
'Content-type':'multipart/form-data',
|
244
|
+
|
245
|
+
'Content-Disposition': 'attachment; filename=file.mp4',
|
246
|
+
|
247
|
+
'X-CSRFToken': csrfToken
|
248
|
+
|
249
|
+
},
|
250
|
+
|
251
|
+
body: data,
|
252
|
+
|
253
|
+
})
|
254
|
+
|
255
|
+
return await toJson(res);
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
```
|
1
記載内容が間違っていたため修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -142,7 +142,7 @@
|
|
142
142
|
|
143
143
|
```
|
144
144
|
|
145
|
-
video_serializer = VideoCreateSerializer(data=request.data)
|
145
|
+
video_serializer = VideoCreateSerializer(data=request.data, video=request.FILES)
|
146
146
|
|
147
147
|
|
148
148
|
|