I'm looking at allowing the user to download PDFs which are stored in the Sitecore media library. Basicaly, I'm sending an email with links to the PDFs which the user can download.
Is this possible? And if so, what URL to use?
We are using Sitecore 8.1, .Net MVC and GlassMapper. In glass mapper Ive tried using the Src property of the File in the Model as the href for the link which gives a path to the ashx file but that doesnt appear to work..
From my GlassMapper model:
[SitecoreField("FileForDownload", UrlOptions = Glass.Mapper.Sc.Configuration.SitecoreInfoUrlOptions.AlwaysIncludeServerUrl)]
public virtual File FileForDownload { get; set; }
The resulting FileForDownload.Src is still giving a relative path which may be causing may issues eg "/~/media/XXX/Annual_Report2004Version2.ashx
This may be an outstanding issue in GlassMapper: enter link description here
The anchor in my email is setup using
<a href='" + pub.FileForDownload.Src + "' download>" + pub.Description + "</a>
Ive also tried using the code
MediaUrlOptions muo = new MediaUrlOptions();
muo.AlwaysIncludeServerUrl = true;
var item = Sitecore.Context.Database.GetItem(new ID(pub.Id));
String url = MediaManager.GetMediaUrl((MediaItem)item, muo);
But thats giving me a url which results in a 404:
http://domainname/-/media/C9F3404515DC46288C5D73E123ACBD5D.ashx