I have an mvc application developed in .net 8.0
I am uploading a audio file through ajax on server, compress it and save it with a new name, This is working fine,
There is an audio tag in my view, whose src attribute i have to upadte to play same audio that recently got uploaded ,
below is my html markup
<audio id="audio" src="" controls style="width:100%"></audio>
And in ajax call within success method
success: function (data) {
debugger
if (data.statuscode == 200) {
var audio = document.getElementById('audio');
var src = data.filepath;
audio.src = src;
audio.load();
audio.play();
} else {
Swal.fire({
title: data.msg,
text: JSON.stringify(data.errors),
icon: "error",
});
}
}
data.filepath return the new path ex : – audio/rtrt.mp3.
audio is a folder under wwwroot directory
Now the Problem is new src also contain action method name in it hence making it invalid
This audio tag is in on index view under dashboard contaroler , so current path in browser is https://port/Dashboard/Index
and when I update the src attribute it became https://port/Dashboard/audio/rtrt.mp3 which is invalid url and audio control failed to load
But if I remove dashboard from url manually , it load the file
https://port/audio/rtrt.mp3 – works
https://port/Dashboard/audio/rtrt.mp3 – does not work
I also tried replacing whole url with below code
var src = window.location.protocola + window.location.host + '/' + data.filepath
It generate the correct url which is also working (https://port/audio/rtrt.mp3)
but when I replace it with src attribute it does not replace the src value , it append in current src value after https://port/Dashboard/
so new src value became https://port/Dashboard/https://port/audio.rtrt.mp3
How to remove Dashboard (default action method name) from src ??
And why https://port/Dashboard/ stay there as a default value ?