|
|
|
@ -143,23 +143,22 @@ class UploadFile(StarletteUploadFile): |
|
|
|
str, |
|
|
|
Doc("The text encoding to use when decoding bytes. Defaults to 'utf-8'."), |
|
|
|
] = "utf-8", |
|
|
|
) -> str: |
|
|
|
|
|
|
|
) -> str: |
|
|
|
""" |
|
|
|
Read the entire file as a text string. |
|
|
|
This is a convenience wrapper around `await self.read()` |
|
|
|
that decodes the bytes using the given encoding. |
|
|
|
## Example |
|
|
|
```python |
|
|
|
@app.post("/upload-text/") |
|
|
|
async def upload_text(file: UploadFile): |
|
|
|
text = await file.read_text() |
|
|
|
return {"length": len(text)} |
|
|
|
``` |
|
|
|
Args: |
|
|
|
encoding: The text encoding to use (default: 'utf-8'). |
|
|
|
Returns: |
|
|
|
The decoded file content as a string. |
|
|
|
Read the entire file as a text string. |
|
|
|
This is a convenience wrapper around `await self.read()` |
|
|
|
that decodes the bytes using the given encoding. |
|
|
|
## Example |
|
|
|
```python |
|
|
|
@app.post("/upload-text/") |
|
|
|
async def upload_text(file: UploadFile): |
|
|
|
text = await file.read_text() |
|
|
|
return {"length": len(text)} |
|
|
|
``` |
|
|
|
Args: |
|
|
|
encoding: The text encoding to use (default: 'utf-8'). |
|
|
|
Returns: |
|
|
|
The decoded file content as a string. |
|
|
|
""" |
|
|
|
data = await self.read() |
|
|
|
return data.decode(encoding) |
|
|
|
|