ZhouliProject/Zhouli.FileService/Controllers/FileController.cs

(开头部分) 2KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Qiniu.Http;
using Qiniu.IO;
using Qiniu.Util;
using Zhouli.Common;
using Zhouli.FileService.Models;

namespace Zhouli.FileService.Controllers
{
    /// <summary>
    /// 文件下载
    /// </summary>
    [Route("[controller]")]
    [ApiController]
    public class FileController : ControllerBase
    {
        private IOptionsSnapshot<CustomConfiguration> _configuration;
        /// <summary>
        /// FileController
        /// </summary>
        /// <param name="configuration"></param>
        public FileController(IOptionsSnapshot<CustomConfiguration> configuration)
        {
            _configuration = configuration;
        }
        /// <summary>
        /// 测试
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Get()
        {
            return Ok("哈哈");
        }
        /// <summary>
        /// 文件访问,返回文件流
        /// </summary>
        /// <param name="fileKey"></param>
        /// <param name="environment"></param>
        /// <returns></returns>
        [HttpGet("{fileKey}")]
        public async Task<FileResult> Download([FromServices]IHostingEnvironment environment, string fileKey)
        {
            byte[] byteData = null;
            //解析fileKey
            Mac mac = new Mac(_configuration.Value.AccessKey, _configuration.Value.SecretKey);
            string rawUrl = $"{_configuration.Value.Bucket.@private.Split(',')[0]}";
            // 设置下载链接有效期3600秒
            int expireInSeconds = 3600;
            string accUrl = DownloadManager.CreateSignedUrl(mac, rawUrl, expireInSeconds);
后面还有 7 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。