Пример #1
0
        public IActionResult Index(string dir, string name)
        {
            name = Path.Combine(dir, name);
            var file = _storageDirectory.GetFile(name);

            if (file == null || !file.Exists)
            {
                return(NotFound());
            }

            return(PhysicalFile(file.FullName, file.Extension.GetContentType()));
        }
Пример #2
0
        /// <summary>
        /// 获取头像文件实例。
        /// </summary>
        /// <param name="userId">用户Id。</param>
        /// <param name="size">宽度或者高度。</param>
        /// <returns>返回文件实例。</returns>
        public IStorageFile GetFile(int userId, int size)
        {
            var defaultFile = _storageDirectory.GetFile($"avatars/{userId}/default.png");

            if (size <= 0 || size == Size)
            {
                return(defaultFile);
            }

            var currentFile = _storageDirectory.GetFile($"avatars/{userId}/{size}.png");

            if (!currentFile.Exists)
            {
                currentFile.Resize(size, size).MoveTo($"{size}.png");
            }

            return(currentFile);
        }
Пример #3
0
        /// <summary>
        /// 获取头像文件实例。
        /// </summary>
        /// <param name="userId">用户Id。</param>
        /// <param name="size">宽度或者高度。</param>
        /// <returns>返回文件实例。</returns>
        public IStorageFile GetFile(int userId, int size)
        {
            var path        = GetPath(userId);
            var defaultFile = _storageDirectory.GetFile(path + "default.png");

            if (size <= 0 || size == Size)
            {
                return(defaultFile);
            }

            var currentFile = _storageDirectory.GetFile(path + $"{size}.png");

            if (!currentFile.Exists)
            {
                currentFile.Resize(size, size).MoveTo($"{size}.png");
            }

            return(currentFile);
        }