Skip to content

HTTP POST base64 #2380

@darrenleeleelee1

Description

@darrenleeleelee1

Example

from fastapi import FastAPI, File, UploadFile
from fastapi.responses import FileResponse
import base64

app = FastAPI()

os.system('chcp')

@app.post("/uploadbase64")
async def post_base64Image(base64_image: str, photo_name: str):
    imgstr = base64_image
    imgdata = base64.b64decode(imgstr)
    filename = '%s.jpg' % photo_name 
    with open(filename, 'wb') as f:
        f.write(imgdata)
    
    return base64_image

Description

Environment

  • macOS
  • FastAPI Version: 0.61.1
  • Python version: 3.8.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions