0

I want to send request from postman to the endpoint below. the request contains a file and json object as input. I tried to make request in postman using key location_details and its values {"location": "name", "latitude": 37.7749,"longitude": -122.4194,"phone_number": "phonenumber"} but the output says value is not a valid dict

i want to send the following data

{
name: name,
location : {
   location_name:location_name,
   latitude:80,
   Longitude:80,
   phone_number:phone_number
}
}

and an image in the request

Router

@router.post(
    "/vendor"
   )
def add_vendor(
        request: VendorSaveRequest= Depends(VendorSaveRequest.as_form),
      

):
    """post new vendor"""

    print (request)
    return request

Schema for location

class LocationSchema(BaseSchema):
   location:str
   latitude:float
   longitude:float
   phone_number:str

schema for request

class VendorSaveRequest(BaseRequest):
    name: str 
    description: Optional[str]
    title: str 
    slug: str 
    logo: Optional[UploadFile]
    location: LocationSchema



    @classmethod
    def as_form(cls,
                name: str = Form(...),
                description: Optional[str] = Form(None),
                title :str = Form(...),
                slug:str = Form(...),
                logo: Optional[UploadFile] = File(None),
                location_details: LocationSchema = Form(...),
            
              ):
        return cls(
            name=name,
            description=description,
            title=title,
            slug=slug,
            logo=logo,
            location_details=location_details,
        )

I tried using postman but it said value is not a valid dict Image of postman

  • 1
    Generally, you don't - you can't combine UploadFile with a JSON body - they're different methods of submitting a form. You can't use `Form` with a JSON body either (so `LocationSchema`) won't work. Either use only JSON (with the file as base64 encoded content) or only regular Form values (with each field by itself) – MatsLindh Aug 14 '23 at 10:49

0 Answers0