* Switch from JSON to multipart file encoding for file upload File upload is detected when body data contains a value of class FileUpload Remaining JSON is converted to FormData Enitre message is sent as multipart * Switch from JSON to multipart file encoding for file upload (#6) File upload is detected when body data contains a value of class FileUpload Remaining JSON is converted to FormData Enitre message is sent as multipart
14 lines
389 B
Python
14 lines
389 B
Python
from httpx._types import FileTypes
|
|
from typing import Sequence, Union
|
|
FileUploadTypes = Union[FileTypes, Sequence[FileTypes]]
|
|
|
|
|
|
class FileUpload:
|
|
def __init__(self, *args):
|
|
self.files: FileUploadTypes = args
|
|
|
|
def get(self, key: str):
|
|
if isinstance(self.files[0], Sequence):
|
|
return tuple((key, i) for i in self.files)
|
|
return ((key, self.files),)
|