For the following Typespec definition about "multipart/form-data":
...
model MultiPartRequest {
id: string;
profileImage: bytes;
}
op basic(@header contentType: "multipart/form-data", @body body: MultiPartRequest): NoContentResponse;
Compared with content-type, the only difference is that we don't generate overload for IO since core can't handle IO which may contain IO, too.
@overload
def basic(self, body: JSON, **kwargs: Any) -> None:
...
@overload
def basic(self, body: _models.MultiPartRequest, **kwargs: Any) -> None:
...
@distributed_trace
def basic(self, body: Union[_models.MultiPartRequest, JSON], **kwargs: Any) -> None:
...
Users could use SDK with the following ways:
...
with open("image.png", "rb") as file:
clent.basic({"id": "123", "profileImage": file})
# or
# clent.basic({"id": "123", "profileImage": file.read()})
def multipart_form_data_file(file: Union[IOBase, bytes]) -> Union[IOBase, Tuple[str, bytes, str]]:
if isinstance(file, IOBase):
return file
return (str(time.time()), file, "application/octet-stream")
def basic(self, body: Union[_models.MultiPartRequest, JSON], **kwargs: Any) -> None:
...
_files = {k: multipart_form_data_file(v) for k, v in body.items() if isinstance(v, (IOBase, bytes))}
_data = {k: v for k, v in body.items() if not isinstance(v, (IOBase, bytes))}
_request = build_multi_part_basic_request(
data=_data,
files=_files,
headers=_headers,
params=_params,
)
...
nit: I make a test locally and it passes with up logic and we don't need change for current azure-core version.
My thinking is with multipart, we should have the option to pass them as splatted keyword only args, i.e.
The reason for this is a lot of the time with multipart form data, we're sending whole files etc. and that to me means we should elevate these properties onto the command line.
I'm not sure if this will be too much with also having a
JSON
and amodels
approach though, but I still do think it seems more pythonic to have them as keyword argscc @johanste @lmazuel @tadelesh
Also since these requests have more of a possibility of being large, we should still have the option for people to stream in the formdata