FastAPI: form-data name with a dot

382 Views Asked by At

I have documentation. Form-data names have dots.

enter image description here

enter image description here

enter image description here

enter image description here

This code doesn't work:

from fastapi import FastAPI, File, UploadFile

app = FastAPI()

@app.post('/test')
async def test(anpr: UploadFile = File(...), 
               licensePlatePicture: UploadFile = File(...),
               detectionPicture: UploadFile = File(...)
              ):
    ''''''
    return None

enter image description here

Question: What if we have form-data name with a dot?

1

There are 1 best solutions below

0
On BEST ANSWER

You can add aliases to your file fields like this:

@app.post('/test')
async def test(anpr: UploadFile = File(..., alias='anpr.xml'),
               licensePlatePicture: UploadFile = File(..., alias='licensePlatePicture.jpg'),
               detectionPicture: UploadFile = File(..., alias='detectionPicture.jpg')
              ):