You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Always prefix the asset path with a forward slash `/` to reference the asset from the root of the project, or it may not display correctly on non-root pages.
35
39
```
36
40
41
+
### 2. Using rx.asset Function
42
+
43
+
The `rx.asset` function provides a more flexible way to reference assets in your app. It supports both local assets (in the app's `assets/` directory) and shared assets (placed next to your Python files).
44
+
45
+
#### Local Assets
46
+
47
+
Local assets are stored in the app's `assets/` directory and are referenced using `rx.asset`:
48
+
49
+
```python demo
50
+
rx.image(src=rx.asset("Reflex.svg"), width="5em")
51
+
```
52
+
53
+
#### Shared Assets
54
+
55
+
Shared assets are placed next to your Python file and are linked to the app's external assets directory. This is useful for creating reusable components with their own assets:
56
+
57
+
```python box
58
+
# my_component.py
59
+
import reflex as rx
60
+
61
+
# my_script.js is located next to this Python file
# Shared assets are linked to your app via symlinks.
84
+
85
+
When using `shared=True`, the asset is symlinked from its original location to your app's external assets directory. This allows you to keep assets alongside their related code.
86
+
```
87
+
37
88
## Favicon
38
89
39
90
The favicon is the small icon that appears in the browser tab.
Copy file name to clipboardExpand all lines: docs/assets/upload_and_download_files.md
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,26 @@ In addition to any assets you ship with your app, many web app will often need t
10
10
11
11
In this section, we will cover all you need to know for manipulating files in Reflex.
12
12
13
+
## Assets vs Upload Directory
14
+
15
+
Before diving into file uploads and downloads, it's important to understand the difference between assets and the upload directory in Reflex:
16
+
17
+
| Feature | Assets | Upload Directory |
18
+
| --- | --- | --- |
19
+
| Purpose | Static files included with your app (images, stylesheets, scripts) | Dynamic files uploaded by users during runtime |
20
+
| Location |`assets/` folder or next to Python files (shared assets) |`uploaded_files/` directory (configurable) |
21
+
| Access Method |`rx.asset()` or direct path reference |`rx.get_upload_url()`|
22
+
| When to Use | For files that are part of your application's codebase | For files that users upload through your application |
23
+
| Availability | Available at compile time | Available at runtime |
24
+
25
+
```md alert
26
+
# Assets are primarily intended for frontend use
27
+
28
+
Assets in Reflex are primarily intended for frontend use and are not expected to be read from the backend. When assets are needed in both frontend and backend, they are currently copied to the backend (though this behavior may change in future versions).
29
+
```
30
+
31
+
For more information about assets, see the [Assets Overview](/docs/assets/overview/).
32
+
13
33
## Download
14
34
15
35
If you want to let the users of your app download files from your server to their computer, Reflex offer you two way.
0 commit comments