Downloaded() public static méthode

public static Downloaded ( int fileId ) : void
fileId int
Résultat void
Exemple #1
0
        /// <summary>
        /// Processes the request.
        /// </summary>
        public async Task ProcessRequestCore()
        {
            if (!CheckPermissions())
            {
                _context.Response.StatusCode = 404;
                return;
            }

            var httpHeaderTools = new HttpHeaderTools(_context);
            var endResponse     = HandleResponseForClientCache(httpHeaderTools);

            if (endResponse)
            {
                return;
            }

            //TODO: CheckExecutableType feature is not ported yet from .net framework Services
            // It was designed to handle executable files like aspx or cshtml.
            // See the Repository.ExecutableExtensions property for the full list.

            //TODO: the ImgResizeApplication feature is not ported yet from .net framework Services

            await InitializeRequestedNodeAsync();

            if (RequestedNode == null)
            {
                _context.Response.StatusCode = 404;
                return;
            }

            using (var binaryStream = GetConvertedStream(out var contentType, out var fileName))
            {
                if (binaryStream == null)
                {
                    return;
                }

                _context.Response.ContentType = contentType;
                _context.Response.Headers.Append(HeaderNames.ContentLength, binaryStream.Length.ToString());

                httpHeaderTools.SetContentDispositionHeader(fileName);
                httpHeaderTools.SetCacheControlHeaders(lastModified: RequestedNode.ModificationDate, maxAge: MaxAge);

                _context.Response.StatusCode = 200;

                binaryStream.Position = 0;

                // Let ASP.NET handle sending bytes to the client.
                ResponseLimiter.AssertFileLength(binaryStream.Length);
                await binaryStream.CopyToAsync(_context.Response.Body);
            }

            // Let the client code log file downloads
            if (RequestedNode is File file)
            {
                File.Downloaded(file.Id);
            }
        }
        public override VirtualFile GetFile(string virtualPath)
        {
            var currentPortalContext = PortalContext.Current;

            // office protocol: instruct microsoft office to open the document without further webdav requests when simply downloading the file
            // webdav requests would cause an authentication window to pop up when downloading a docx
            if (HttpContext.Current != null && HttpContext.Current.Response != null)
            {
                if (WebApplication.DownloadExtensions.Any(extension => virtualPath.EndsWith(extension, StringComparison.InvariantCultureIgnoreCase)))
                {
                    // we need to do it this way to support a 'download' query parameter with or without a value
                    var queryParams = HttpContext.Current.Request.QueryString.GetValues(null);
                    var download    = HttpContext.Current.Request.QueryString.AllKeys.Contains("download") || (queryParams != null && queryParams.Contains("download"));

                    if (download)
                    {
                        var fName = string.Empty;

                        if (currentPortalContext != null && currentPortalContext.IsRequestedResourceExistInRepository)
                        {
                            // look for a content
                            var node = Node.LoadNode(virtualPath);
                            if (node != null)
                            {
                                fName = DocumentBinaryProvider.Current.GetFileName(node);
                            }
                        }
                        else
                        {
                            // look for a file in the file system
                            fName = Path.GetFileName(virtualPath);
                        }

                        HttpHeaderTools.SetContentDispositionHeader(fName);
                    }
                }
            }

            if (WebApplication.DiskFSSupportMode == DiskFSSupportMode.Prefer && base.FileExists(virtualPath))
            {
                var result = base.GetFile(virtualPath);

                // let the client code log file downloads
                if (PortalContext.Current != null && PortalContext.Current.ContextNodePath != null &&
                    string.Compare(virtualPath, PortalContext.Current.ContextNodePath, StringComparison.Ordinal) == 0)
                {
                    File.Downloaded(virtualPath);
                }

                return(result);
            }

            // Indicates that the VirtualFile is requested by a HttpRequest (a Page.LoadControl also can be a caller, or an aspx for its codebehind file...)
            var isRequestedByHttpRequest =
                (HttpContext.Current != null) && (string.Compare(virtualPath, HttpContext.Current.Request.Url.LocalPath, StringComparison.InvariantCultureIgnoreCase) == 0);

            if (isRequestedByHttpRequest && currentPortalContext.IsRequestedResourceExistInRepository)
            {
                return(new RepositoryFile(virtualPath, currentPortalContext.RepositoryPath));
            }
            else if (IsFileExistsInRepository(virtualPath))
            {
                return(new RepositoryFile(virtualPath, virtualPath));
            }
            else if (IsFileExistsInAssembly(virtualPath))
            {
                return(new EmbeddedFile(virtualPath));
            }
            else
            {
                // Otherwise it may exist in the filesystem - call the base
                return(base.GetFile(virtualPath));
            }
        }