C# Web MVC + Angular
I have the below link on my web page:
<a ng-show="channel.ArtistImagepath != null" ng-href="/channel/DownloadImageFile/?filepath={{channel.ArtistImagepath}}" target="_blank"><i class="fa fa-download" style="color: green"></i> Artist Image</a><br/>
When I copy the link in my browser it is:
//mysite/channel/DownloadImageFile/?filepath=ChannelUploads/b51535d5-4ea3-45ae-bda4-332a0ce19ee8Artist+Gomez.jpg
When I click on the link the filepath sent to my controller is: ChannelUploads/b51535d5-4ea3-45ae-bda4-332a0ce19ee8ArtistDina Gomez.jpg
As you can see the + sign is replaced with a space in the filename because the URL is encoded. This results in a file not found error message..the actual filename existing on my server is: b51535d5-4ea3-45ae-bda4-332a0ce19ee8Artist+Gomez.jpg
public ActionResult DownloadImageFile(string filepath)
{
filepath = "https://marvment.com/" + filepath;
var type = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
var path = Path.GetFileName(filepath);
path = HttpUtility.UrlEncode(path);
//path = ToUrlFriendlyString(path);
using (var client = new WebClient())
{
var buffer = client.DownloadData(filepath);
return File(buffer, type.ToString(), path);
}
}
How can I prevent the file name from beign URL encoded before sending it to my controller? I want to keep the + sign in the filename and handle the encoding in my MVC controller.