Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have data drive with folders of .mp3 files with .csv as database (written by another program to a data drive)

I created a Blazor Server app that displays the .csv data in a table, including the path to the file. How can I create a link in the table to download the file since it is not in the wwwroot folder?

What I have tried:

I have looked into UseStaticFiles and got lost understanding offering downloads with an API.

Would anyone suggest I continue with either, or possibly another way?
Posted
Updated 24-Jul-23 5:59am

1 solution

You cannot create a link direct to a file outside the apps own directory. This is for security reasons.

You can, however, create a link to a code on the server-side to tell it which file to download and that code would have to read the file and return it. The server-side code would have to build the path and the account running your code on the server would have to have proper permissions to the folder containing your files to download.
 
Share this answer
 
Comments
NewButTryingHard 24-Jul-23 13:58pm    
Thank you. I have been really googling "read the file and return it". I believe that would look something like:

@code {
public Byte[] DownloadFile()
{
Byte[] bytes = File.ReadAllBytes("D:\\Recordings\\a.mp3");

return File(bytes, "audio/mp3");
}
}

Am I even in the ballpark?
Dave Kreskowiak 24-Jul-23 16:07pm    
I haven't done Blazor anything yet so I don't know. What happens when you try it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900