I am developing a Flutter web application hosted at:
http://www.academy.co.kr/song_check/tep/
The app works perfectly when accessed directly via:
http://www.academy.co.kr/song_check/tep/web/
I have set the baseHref to /song_check/tep/web/ during the build process to ensure assets like images, fonts, and audio files load correctly. Here’s the build command I used:
flutter build web --base-href /song_check/tep/web/
With this setup, all assets (images, fonts, and audio) load successfully. However, the issue arises when I access the app with a query parameter in the URL, such as:
http://www.academy.co.kr/song_check/tep/web/?academyName=Test%20Academy
The Problem:
When the app is accessed with a query parameter, audio files fail to load, while images and fonts still load correctly. Here is the behavior I observed:
Expected audio file URL:
http://www.academy.co.kr/song_check/tep/web/assets/sounds/common/b_opening.mp3
Actual audio file request (as seen in the browser’s Network tab):
http://www.academy.co.kr/song_check/tep/web/?academyName=Test%20Academy/assets/sounds/common/b_opening.mp3
This results in a 404 Not Found error. Interestingly, the logs in the browser console display the correct audio URL, but the network request includes the query parameter, which breaks the path.
My Questions:
How can I ensure that audio files (e.g., MP3) load correctly, even when the URL includes query parameters?
I added logs in my Flutter application to debug the issue. When I printed the audio asset URL before making the network request, I saw the following in the browser console:
Correct audio URL: http://www.academy.co.kr/song_check/tep/web/assets/sounds/common/b_opening.mp3
However, in the Network tab of the browser’s developer tools, I noticed that the actual request included the query parameter in the path, resulting in:
http://www.academy.co.kr/song_check/tep/web/?academyName=Test%20Academy/assets/sounds/common/b_opening.mp3
I was expecting the network request to use the correct URL as logged in the console, without including the query parameter in the asset path.
My Questions:
How can I ensure that audio files (e.g., MP3) load correctly, even when the URL includes query parameters?
ddpapa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.