I currently have an HTML page that contains a link:
<a href="javascript:void()" onclick="return getAudioFile('fileLocation');">Listen</a>
Clicking the "Listen" link calls this function:
function getRecordingFile(fileLocation) {
};
Which should ultimately call this controller method:
[HttpPost]
public ActionResult GetAudioFile(string fileLocation)
{
return null;
}
I have emptied out the function and method because I have tried several different things to accomplish this: I need to access an audio file from a local location and allow the user to listen to it/download it upon clicking the Listen link.
What seems to be the best way to go about this?
Here is the final result:
[HttpGet]
public ActionResult GetAudioFile(string fileLocation)
{
var bytes = new byte[0];
using (var fs = new FileStream(fileLocation, FileMode.Open, FileAccess.Read)
{
var br = new BinaryReader(fs);
long numBytes = new FileInfo(fileLocation).Length;
buff = br.ReadBytes((int)numBytes);
}
return File(buff, "audio/mpeg", "callrecording.mp3");
}
On the page, the link is:
<a href="/Controller/GetAudioFile?fileName=@fileLocation">Listen</a>
Kudos to my boss for the help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With