I'm trying to upload a video to FastAPI, however, an error occurs.
This is my python code.
from fastapi import FastAPI, File, UploadFile
from typing import List
import os
app = FastAPI()
@app.get("/")
def read_root():
return { "Hello": "World" }
@app.post("/files/")
async def create_files(files: List[bytes] = File(...)):
return {"file_sizes": [len(file) for file in files]}
@app.post("/uploadfiles")
async def create_upload_files(files: List[UploadFile] = File(...)):
print('here')
UPLOAD_DIRECTORY = "./"
for file in files:
contents = await file.read()
with open(os.path.join(UPLOAD_DIRECTORY, file.filename), "wb") as fp:
fp.write(contents)
print(file.filename)
return {"filenames": [file.filename for file in files]}
When I use Postman, the image is uploaded fine, but the video is not.
This is the error:
INFO: 127.0.0.1:57251 - "POST /uploadfiles/ HTTP/1.1" 307 Temporary Redirect
Did not find boundary character 254 at index 2
INFO: 127.0.0.1:57252 - "POST /uploadfiles HTTP/1.1" 400 Bad Request
Please tell me what is the problem.