public async Task <IActionResult> DownloadFile(DownloadFileAddressModel model)
        {
            var download     = !string.IsNullOrWhiteSpace(model.Sd);
            var targetBucket = await _dbContext.Bucket.SingleOrDefaultAsync(t => t.BucketName == model.BucketName);

            if (targetBucket == null || !targetBucket.OpenToRead)
            {
                return(NotFound());
            }
            var targetFile = await _dbContext
                             .OSSFile
                             .Where(t => t.BucketId == targetBucket.BucketId)
                             .SingleOrDefaultAsync(t => t.RealFileName == model.FileName + "." + model.FileExtension);

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

            // Update download times
            targetFile.DownloadTimes++;
            await _dbContext.SaveChangesAsync();

            var path = _configuration["StoragePath"] + $"{_}Storage{_}{targetBucket.BucketName}{_}{targetFile.FileKey}.dat";

            return(await ReturnFile(path, model.H, model.W, targetFile.RealFileName, download, model.Name));
        }
        public async Task <IActionResult> DownloadFile(DownloadFileAddressModel model)
        {
            var download     = !string.IsNullOrWhiteSpace(model.sd);
            var targetBucket = await _dbContext.Bucket.SingleOrDefaultAsync(t => t.BucketName == model.BucketName);

            var targetFile = await _dbContext
                             .OSSFile
                             .Where(t => t.BucketId == targetBucket.BucketId)
                             .SingleOrDefaultAsync(t => t.RealFileName == model.FileName + "." + model.FileExtension);

            if (targetBucket == null || targetFile == null || !targetBucket.OpenToRead)
            {
                return(NotFound());
            }
            // Update download times
            targetFile.DownloadTimes++;
            await _dbContext.SaveChangesAsync();

            var path = _configuration["StoragePath"] + $"{_}Storage{_}{targetBucket.BucketName}{_}{targetFile.FileKey}.dat";

            try
            {
                if (StringOperation.IsImage(targetFile.RealFileName) && model.h > 0 && model.w > 0)
                {
                    return(await this.AiurFile(await _imageCompresser.Compress(path, targetFile.RealFileName, model.w, model.h), targetFile.RealFileName));
                }
                else
                {
                    return(await this.AiurFile(path, targetFile.RealFileName, download));
                }
            }
            catch (Exception e) when(e is DirectoryNotFoundException || e is FileNotFoundException)
            {
                return(NotFound());
            }
        }