updated readme
This commit is contained in:
41
README.md
41
README.md
@@ -75,38 +75,39 @@ data_table = await DataTable.create(api_endpoint="/api/users")
|
||||
### Additional Components
|
||||
|
||||
#### FileDrop
|
||||
Drag-and-drop file upload component with customizable styling:
|
||||
Drag-and-drop file upload component with visual feedback:
|
||||
|
||||
```python
|
||||
from niceguiex.components import FileDrop
|
||||
|
||||
def handle_files(files: List[Dict[str, Any]]):
|
||||
# For multiple files
|
||||
for file in files:
|
||||
print(f"File: {file['name']}, Size: {file['size']}")
|
||||
# Access content with file['content']
|
||||
async def handle_upload(name: str, file_type: str, content: bytes):
|
||||
"""Handle uploaded file"""
|
||||
print(f"File: {name}, Type: {file_type}, Size: {len(content)} bytes")
|
||||
# Process the file content
|
||||
with open(f'uploads/{name}', 'wb') as f:
|
||||
f.write(content)
|
||||
|
||||
def handle_single_file(file: Dict[str, Any]):
|
||||
# For single file mode, returns dict directly
|
||||
print(f"Uploaded: {file['name']}")
|
||||
# Use file['path'] if return_content=False for large files
|
||||
# Basic usage
|
||||
FileDrop(
|
||||
on_upload=handle_upload,
|
||||
multiple=False,
|
||||
accept='.pdf,.txt,.docx'
|
||||
)
|
||||
|
||||
# Multiple files
|
||||
FileDrop(
|
||||
on_upload=handle_files,
|
||||
on_upload=handle_upload,
|
||||
multiple=True,
|
||||
accept='.pdf,.txt,.docx',
|
||||
max_size=5 # 5MB limit
|
||||
)
|
||||
|
||||
# Single file with temp path (for large files)
|
||||
FileDrop(
|
||||
on_upload=handle_single_file,
|
||||
multiple=False,
|
||||
return_content=False # Returns temp file path instead of content
|
||||
accept='image/*'
|
||||
)
|
||||
```
|
||||
|
||||
Features:
|
||||
- Visual drag-over feedback
|
||||
- Click to browse or drag & drop
|
||||
- Customizable file type filtering
|
||||
- Async callback support
|
||||
|
||||
#### ImageDrop
|
||||
Specialized file drop for images that returns PIL Image objects:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user