here is the call...
return new FileUriResult("application/octet-stream", a.AssetPath, null);
[note that I set content length to null because I don't know it (file is on another server)]
a.AssetPath is: "http://http.cdnlayer.com/account name/folder/folder/folder/asset.mp3"
(fake URL for this example but in my implementation I can browse the file directly, however this attachment method is not working)
here is the implementation...
public class FileUriResult : ActionResult
{
private string _contentType;
private string _fileUri;
private long? _fileLength;
public FileUriResult(string contentType, string fileUri, long? fileLength)
{
_contentType = contentType;
_fileUri = fileUri;
_fileLength = fileLength;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = _contentType;
response.AddHeader("Content-Disposition", "attachment; filename=" + _fileUri);
if(_fileLength != null)
response.AddHeader("Content-Length", _fileLength.ToString());
}
}
The file is being directly downloaded just like I want (not opened by browser) however it is NOT the file, it is simply a 0kb file with the same name.