Ejemplo 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
            FileId    fileId = FileId.FromUuid(id);
            IFileInfo info   = _fileProvider.GetFile(fileId.PhysicalPath);

            if (!info.Exists)
            {
                return(NotFound());
            }

            AddHttpLinkHeader(fileId);

            await Context.Response.WriteFileContentAsync(fileId.PhysicalPath, _fileProvider);

            return(new EmptyResult());
        }
Ejemplo n.º 2
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());
        }