Exemplo n.º 1
0
        public async Task <IActionResult> Get(string id)
        {
            //
            // Check for redirect
            var redirect = _redirectService.GetRedirect(id);

            if (redirect != null)
            {
                return(new RedirectResult(redirect.To(), redirect.Permanent));
            }

            //
            // Serve content
            var dl = _downloadService.Get(id);

            if (dl == null)
            {
                return(NotFound());
            }

            if (!_fileProvider.GetFile(dl.PhysicalPath).Exists)
            {
                _downloadService.Remove(dl.Id);
                return(NotFound());
            }

            bool inline = Context.Request.Query["inline"].Count > 0;

            IHeaderDictionary headers = new HeaderDictionary();

            headers.SetContentDisposition(inline, Path.GetFileName(dl.PhysicalPath));

            await Context.Response.WriteFileContentAsync(dl.PhysicalPath, _fileProvider, headers);

            return(new EmptyResult());
        }