Skip to content

HTTP POST image, how to interact with it? #2216

@darrenleeleelee1

Description

@darrenleeleelee1

Example

from fastapi import FastAPI, File, UploadFile
from fastapi.responses import FileResponse
from pydantic import BaseModel
import numpy as np
import shutil
app = FastAPI()


@app.get("/")
async def main():
    return FileResponse(r"misdo.jpg")


@app.post("/uploadfile/")
async def create_upload_file(image: UploadFile = File(...)):
    with open("destination.jpg", "wb") as buffer:
         shutil.copyfileobj(image.file, buffer)
    return image.filename`

Description

  • This code is work fine in 127.0.0.1:8000/docs.

  • But I am wondering how can I post without using 127.0.0.1:8000/docs.

  • More specified is how could I use other languague(Swift) to interact with this API.

  • I know how to do with HTTP.GET, but HTTP.POST still bothering me.

  • Or is my POST funtion is not well defined?

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