from fastapi import FastAPI
from fastapi import File, UploadFile
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*']
)
@app.post('/api')
def post(
files: UploadFile = File(...)
):
print('post')
return dict(status='ok')
from fastapi.testclient import TestCient
testclient = TestClient(app)
files = list()
for path in files_path:
with open(path, 'rb') as f:
files.append('files', f.read())
res = testclient.post(/api, files=files)