#Images are not found when I work with the `asset!` macro

1 messages · Page 1 of 1 (latest)

glad hawk
#

If I compile my application using cargo run, the application starts. The configured css file is accepted. The absolute paths to the images on my system are shown in the inspector. The files are found but not displayed. In the inspector I can see under Notwork that this message appears in the Security tab:

The resource was requested insecurely.

If I start the binary from the target/debug directory, the paths are different and the images are not found. When I open the inspector, I see this information in the Console tab:

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (main-80abd743cc2a0d09.css, line 0)
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (working_desk-c265ae2c0bbb84b7.webp, line 0)

In the Network Tab the links look like this:

Summary
URL: dioxus://index.html/assets/working_desk-c265ae2c0bbb84b7.webp
Status: —
Source: —

How can I ensure that the required resources are found and displayed?

desert hazel
#

You need to bundle assets with dx. cargo run doesn't know about the asset system

#

It should work with dx serve

glad hawk
#

can you link me a guide, how to do that please?

desert hazel
#

how to run dx serve?

glad hawk
#

I had not installed and used the dioxus-cli toolchain before. I have now done this and have to realise that the assets are now delivered in an assets folder with the binary. the path to the binary after executing the dx serve command is:
target/dx/my_project/debug/linux/app

In this case I can simply continue to work directly with my res directory and must pass the directory in the configuration via with_resource_directory:

.with_resource_directory(binary_path.parent().unwrap().join(‘res’))

In any case, the images are recognised, but not loaded and displayed. I suspect that it is due to the text The resource was requested insecurely.. What is the reason for this and how can I ensure that the images are displayed again?