UploadFile
A file uploaded in a request.
Attributes
| Attribute | Type | Description |
|---|---|---|
| file | BinaryIO | The standard Python file object (non-async). |
| filename | `str | None` |
| size | `int | None` |
| headers | Headers | The headers of the request. |
| content_type | `str | None` |
Constructor
Signature
def UploadFile(
file: BinaryIO,
filename: str | None,
size: int | None,
headers: Headers,
content_type: str | None
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| file | BinaryIO | The standard Python file object (non-async). |
| filename | `str | None` |
| size | `int | None` |
| headers | Headers | The headers of the request. |
| content_type | `str | None` |
Methods
write()
@classmethod
def write(
data: bytes
) - > None
Write some bytes to the file. You normally wouldn't use this from a file you read in a request. To be awaitable, compatible with async, this is run in threadpool.
Parameters
| Name | Type | Description |
|---|---|---|
| data | bytes | The bytes to write to the file. |
Returns
| Type | Description |
|---|---|
None | Nothing is returned after the write operation completes |
read()
@classmethod
def read(
size: int = -1
) - > bytes
Read some bytes from the file. To be awaitable, compatible with async, this is run in threadpool.
Parameters
| Name | Type | Description |
|---|---|---|
| size | int = -1 | The number of bytes to read from the file. |
Returns
| Type | Description |
|---|---|
bytes | The bytes read from the file up to the specified size |
seek()
@classmethod
def seek(
offset: int
) - > None
Move to a position in the file. Any next read or write will be done from that position. To be awaitable, compatible with async, this is run in threadpool.
Parameters
| Name | Type | Description |
|---|---|---|
| offset | int | The position in bytes to seek to in the file. |
Returns
| Type | Description |
|---|---|
None | Nothing is returned after the file pointer is moved |
close()
@classmethod
def close() - > None
Close the file. To be awaitable, compatible with async, this is run in threadpool.
Returns
| Type | Description |
|---|---|
None | Nothing is returned after the file is closed |