0

Does anyone have a code for me so that I can upload a file and work with the file e.g. can call os from the tmp folder?

My code up to now gives some http erros:

from typing import List

from fastapi import FastAPI, File, UploadFile
from fastapi.responses import HTMLResponse

app = FastAPI()


@app.post("/import_file")
async def import_file_post(file: UploadFile = File(...)):
    return {"filename": file.filename}


@app.get("/")
async def main():
    content = """
    <label for="myfile">Select a file:</label>
    <form action="/import_file/" enctype="multipart/form-data" method="post">
        <input name="files" type="file">
        <input type="submit">
    </form>
    """

Thank you!

I have tryed it with some blocks of the doc but it actually doesnt work at me :(

Flouu
  • 45
  • 4
  • Related posts can also be found [here](https://stackoverflow.com/a/70667530/17865804), as well as [here](https://stackoverflow.com/a/73443824/17865804) and [here](https://stackoverflow.com/a/70640522/17865804). – Chris Nov 03 '22 at 13:41

0 Answers0