ABP VNext使用BlobMinio会存在上传没问题,但是查看文件会是下载的问题

ABP VNext使用BlobMinio会存在上传没问题,但是查看文件会是下载的问题

主要原因是Minio会把Content-Type设置成application/octet-stream

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VYUzjTHw-1649841171403)
在这里插入图片描述

因此不能使用ABP Vnext中的BlobMinio,因为它没有给content参数

解决方案:自己写方法

using System;
using System.IO; 
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Minio;
using Minio.Exceptions;
using Volo.Abp;
using Volo.Abp.BlobStoring;
using Volo.Abp.BlobStoring.Minio;
using Volo.Abp.DependencyInjection;

namespace Titan.Blob
{
    public class FileSystemBlobManager : ITransientDependency
    {
        private readonly IHostingEnvironment _env;
        private readonly IConfigurationRoot _appConfiguration;

        public FileSystemBlobManager( [NotNull] IHostingEnvironment env)
        {
            _appConfiguration = GetAppConfiguration(env.ContentRootPath);
        }

        private IConfigurationRoot GetAppConfiguration(string path)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(path)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);

            builder = builder.AddEnvironmentVariables();

            return builder.Build();
        }

        public async Task<string> SaveFile(string name, Stream file,string contentType)
        { 

            var endPoint = _appConfiguration["MinIo:EndPoint"];
            var accessKey = _appConfiguration["MinIo:AccessKey"];
            var secretKey = _appConfiguration["MinIo:SecretKey"];
            var bucketName = _appConfiguration["MinIo:BucketName"];
            try
            {
                var minio = new MinioClient(endPoint, accessKey, secretKey);
                //判断桶(文件夹)是否存在
                bool found = await minio.BucketExistsAsync(bucketName);
                if (!found)
                {
                    //新增桶(文件夹)
                    await minio.MakeBucketAsync(bucketName, "host");
                }
                //文件大小
                var len = file.Length;
                //上传文件到桶(文件夹).
                await minio.PutObjectAsync(bucketName, name, file, len, contentType, null, null);
                //返回url  7天到期
                var url = await minio.PresignedGetObjectAsync(bucketName, name, 3600 * 24 * 7);
                return url;
            }
            catch (MinioException ex)
            {
                throw new Exception(ex.Message);
            }
        }

        
       

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值