diff --git a/20220330_Vote/Ewide.Web.Core/Ewide.Web.Core.csproj b/20220330_Vote/Ewide.Web.Core/Ewide.Web.Core.csproj
index ca21423..9c47a70 100644
--- a/20220330_Vote/Ewide.Web.Core/Ewide.Web.Core.csproj
+++ b/20220330_Vote/Ewide.Web.Core/Ewide.Web.Core.csproj
@@ -14,6 +14,7 @@
+
diff --git a/20220330_Vote/Ewide.Web.Core/Startup.cs b/20220330_Vote/Ewide.Web.Core/Startup.cs
index 7239c9d..d2a9dfc 100644
--- a/20220330_Vote/Ewide.Web.Core/Startup.cs
+++ b/20220330_Vote/Ewide.Web.Core/Startup.cs
@@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+using OnceMi.AspNetCore.OSS;
using Serilog;
using System.Text.Json;
using System.Threading.Tasks;
@@ -67,6 +68,7 @@ namespace Ewide.Web.Core
// 设置雪花id的workerId,确保每个实例workerId都应不同
//var workerId = ushort.Parse(App.Configuration["SnowId:WorkerId"] ?? "1");
//IDGenerator.SetIdGenerator(new IDGeneratorOptions { WorkerId = workerId });
+ services.AddOSSService("HuaweiCloud", "OSSProvider");
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
diff --git a/20220330_Vote/Ewide.Web.Entry/Program.cs b/20220330_Vote/Ewide.Web.Entry/Program.cs
index 0bc9fe8..7f7ce45 100644
--- a/20220330_Vote/Ewide.Web.Entry/Program.cs
+++ b/20220330_Vote/Ewide.Web.Entry/Program.cs
@@ -16,6 +16,10 @@ namespace Ewide.Web.Entry
{
webBuilder.Inject()
.UseStartup();
+ //.UseKestrel(options =>
+ //{
+ // options.Limits.MaxRequestBodySize = null; // null Dzƣֵ M
+ //});
})
.UseSerilogDefault();
}
diff --git a/20220330_Vote/Ewide.Web.Entry/appsettings.json b/20220330_Vote/Ewide.Web.Entry/appsettings.json
index b0d8f31..fce28ee 100644
--- a/20220330_Vote/Ewide.Web.Entry/appsettings.json
+++ b/20220330_Vote/Ewide.Web.Entry/appsettings.json
@@ -33,7 +33,15 @@
"WithOrigins": [ "http://localhost:8080", "https://mapi.zjzwfw.gov.cn" ]
},
"AppSettings": {
- "InjectSpecificationDocument": false
+ "InjectSpecificationDocument1": false
+ },
+ "OSSProvider": {
+ "Provider": "HuaweiCloud", //枚举值支持:Minio/Aliyun/QCloud
+ "Endpoint": "http://10.74.25.87:6020", //腾讯云中表示AppId
+ "Region": "", //地域
+ "AccessKey": "C4D30C2801D928AAF687",
+ "SecretKey": "ooZVXaB1tqIz7DHTv53RILD7o5cAAAGAAdkoqlR2",
+ "IsEnableCache": true //是否启用缓存,推荐开启
}
}
\ No newline at end of file
diff --git a/20220330_Vote/Ewide.Web.Entry/web.config b/20220330_Vote/Ewide.Web.Entry/web.config
new file mode 100644
index 0000000..0d07ddd
--- /dev/null
+++ b/20220330_Vote/Ewide.Web.Entry/web.config
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/20220330_Vote/Vote.Services/ApiController/HuaweiService.cs b/20220330_Vote/Vote.Services/ApiController/HuaweiService.cs
new file mode 100644
index 0000000..4422d9f
--- /dev/null
+++ b/20220330_Vote/Vote.Services/ApiController/HuaweiService.cs
@@ -0,0 +1,278 @@
+using Ewide.Core;
+using Furion.DynamicApiController;
+using Furion.VirtualFileServer;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+using Newtonsoft.Json;
+using NPOI.OpenXml4Net.OPC.Internal;
+using OBS;
+using OBS.Model;
+using OnceMi.AspNetCore.OSS;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Text;
+using System.Threading.Tasks;
+using Vote.Services.Dto;
+
+namespace Vote.Services.ApiController
+{
+ ///
+ /// OBS
+ ///
+ [ApiDescriptionSettings("huawei", Order = 0)]
+ [Route("/huawei")]
+ [AllowAnonymous]
+ public class HuaweiService : IDynamicApiController
+ {
+ private readonly IOSSService _OSSService;
+ private readonly string _bucketName;
+ private readonly string filePrefix;
+ ///
+ ///
+ ///
+ ///
+ public HuaweiService(IOSSService OSSService)
+ {
+ _OSSService = OSSService;
+ _bucketName = "94.229";
+ filePrefix = "D:\\obsFile\\";
+ }
+ ///
+ /// 列出当前账号下允许访问的所有储存桶。
+ ///
+ ///
+ public async Task ListBuckets()
+ {
+ try
+ {
+ var result = await _OSSService.ListBucketsAsync();
+ return result;
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+ }
+ ///
+ /// 获取储存桶的外部访问权限。
+ ///
+ ///
+ public async Task GetBucketAclAsync()
+ {
+ try
+ {
+ var result = await _OSSService.GetBucketAclAsync(_bucketName);
+ return result;
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+ }
+ ///
+ /// 获取指定储存桶中指定对象是否存在。
+ ///
+ ///
+ public async Task ObjectsExistsAsync([FromBody] GetObjectInput args)
+ {
+ if (args == null || string.IsNullOrWhiteSpace(args.objectName))
+ return await Display(false, "error");
+ try
+ {
+ var objectName = args.objectName;
+ if (objectName.ToLower().EndsWith(".dwg"))
+ {
+ objectName += ".zip";
+ }
+ var result = await _OSSService.ObjectsExistsAsync(_bucketName, objectName);
+ return result;
+ }
+ catch (Exception ex)
+ {
+ throw;
+ }
+ }
+ ///
+ /// 获取文件的数据流。 大小写敏感!
+ ///
+ ///
+ [HttpPost]
+ public async Task DownloadObjectAsync([FromBody] GetObjectInput args)
+ {
+ if (args == null || string.IsNullOrWhiteSpace(args.objectName))
+ return await Display(false, "error");
+ var objectName = args.objectName;
+ if (objectName.ToLower().EndsWith(".dwg"))
+ {
+ objectName += ".zip";
+ }
+ #region MyRegion
+ //FileStreamResult fileStreamResult = null;
+ //await _OSSService.GetObjectAsync(_bucketName, objectName, (stream) =>
+ //{
+ // if (FS.TryGetContentType(objectName, out var contentType) || GetContentType(objectName, out contentType))
+ // fileStreamResult = new FileStreamResult(stream, contentType) { FileDownloadName = objectName };
+ //});
+ //if (fileStreamResult != null)
+ // return fileStreamResult;
+ //else
+ // return await Display(false, "文件格式有问题");
+ //var localPath = filePrefix + _bucketName + '/' + args.objectName;
+ //await _OSSService.GetObjectAsync(_bucketName, args.objectName, localPath);
+ //if (FS.TryGetContentType(args.objectName, out var contentType) || GetContentType(args.objectName, out contentType))
+ //{
+ // return new FileStreamResult(new FileStream(localPath, FileMode.Open), contentType) { FileDownloadName = args.objectName };
+ //}
+ //else
+ //{
+ // return await Display(false, "文件格式有问题");
+ //}
+ #endregion
+ #region 原始华为sdk
+ try
+ {
+ //var objectName = "/files/coc/202011/11/2020kdfj0075_5.pdf";
+ ObsClient client = new ObsClient(_OSSService.Options.AccessKey, _OSSService.Options.SecretKey, _OSSService.Options.Endpoint);
+ GetObjectRequest request = new GetObjectRequest()
+ {
+ BucketName = _bucketName,
+ ObjectKey = objectName,
+ };
+ using (GetObjectResponse response = client.GetObject(request))
+ {
+ if (FS.TryGetContentType(objectName, out var contentType) || GetContentType(objectName, out contentType))
+ {
+ //var localPath = filePrefix + _bucketName + '/' + objectName;
+ //if (!File.Exists(localPath))
+ //{
+ // response.WriteResponseStreamToFile(localPath);
+ //}
+ //return new FileStreamResult(new FileStream(localPath, FileMode.Open), contentType) { FileDownloadName = objectName };
+ var ms = new MemoryStream();
+ await response.OutputStream.CopyToAsync(ms);
+ ms.Position = 0;
+ response.OutputStream.Close();
+ response.OutputStream.Dispose();
+ return new FileStreamResult(ms, contentType) { FileDownloadName = objectName };
+
+ }
+ else
+ {
+ return await Display(false, "文件格式有问题");
+ }
+ }
+ }
+ catch (ObsException ex)
+ {
+ throw;
+ }
+ #endregion
+
+ }
+ private bool GetContentType(string filename, out string contenttype)
+ {
+ contenttype = "";
+ bool rslt = true;
+ if (filename.ToLower().EndsWith(".dwg"))
+ {
+ contenttype = "application/octet-stream";
+ }
+ else
+ rslt = false;
+ return rslt;
+ }
+ ///
+ /// 上传文件的数据流。 大小写敏感!
+ ///
+ ///
+ [HttpPost]
+ [DisableRequestSizeLimit]
+ public async Task PutObjectAsync([FromBody] PutObjectInput args)
+ {
+ if (args == null || string.IsNullOrWhiteSpace(args.path))
+ return new ObsApiOutput(false, "参数为空");
+ var file = new FileInfo(args.path);
+ if (!file.Exists)
+ return new ObsApiOutput(false, "文件不存在");
+ var objectName = args.objectName;
+ var path = args.path;
+ if (string.IsNullOrWhiteSpace(args.objectName))
+ objectName = file.Name;
+ try
+ {
+ #region dwg压缩处理
+ var zipRslt = false;
+ if (path.ToLower().EndsWith(".dwg"))
+ {
+ if (new Tools.ZipHelper().ZipOneFile(path, 0))
+ {
+ zipRslt = true;
+ path += ".zip";
+ objectName += ".zip";
+ }
+ }
+ #endregion
+ var r = await _OSSService.PutObjectAsync(_bucketName, objectName, path);
+ if (r && zipRslt)
+ {
+ new FileInfo(path).Delete();
+ }
+ return new ObsApiOutput(r, r ? "上传成功" : "上传失败");
+ }
+ catch (ObsException ex)
+ {
+ return new ObsApiOutput(false, "错误状态码:" + ex.StatusCode);
+ }
+ catch (Exception ex)
+ {
+ return new ObsApiOutput(false, "异常信息:" + ex.Message + ex.StackTrace);
+ }
+ }
+ private async Task Display(bool isSuccess, object data)
+ {
+ return DisplayJson(new RestfulResult
diff --git a/20220330_Vote/Vote.Services/Vote.Services.xml b/20220330_Vote/Vote.Services/Vote.Services.xml
index 71c38d9..a5b71c9 100644
--- a/20220330_Vote/Vote.Services/Vote.Services.xml
+++ b/20220330_Vote/Vote.Services/Vote.Services.xml
@@ -4,6 +4,47 @@
Vote.Services
+
+
+ OBS
+
+
+
+
+
+
+
+
+
+
+ 列出当前账号下允许访问的所有储存桶。
+
+
+
+
+
+ 获取储存桶的外部访问权限。
+
+
+
+
+
+ 获取指定储存桶中指定对象是否存在。
+
+
+
+
+
+ 获取文件的数据流。 大小写敏感!
+
+
+
+
+
+ 上传文件的数据流。 大小写敏感!
+
+
+
项目
@@ -56,6 +97,31 @@
+
+
+
+
+
+
+
+ 大小写敏感!
+
+
+
+
+
+
+
+
+
+ 本地文件全路径
+
+
+
+
+ 希望上传到的目录和文件名 , 如果为空则上传到根目录 ,大小写敏感! ,斜杠必须使用/ , eg: files/COC/202011/11/2020KDFJ0075.pdf
+
+
项目类型
@@ -343,5 +409,42 @@
+
+
+
+
+
+
+
+ 所有文件缓存
+
+
+
+
+ 所有空目录缓存
+
+
+
+
+ 取得目录下所有文件及文件夹,分别存入files及paths
+
+ 根目录
+
+
+
+ 压缩目录(包括子目录及所有文件)
+
+ 要压缩的根目录
+ 保存路径
+ 压缩程度,范围0-9,数值越大,压缩程序越高
+
+
+
+ 压缩单个文件
+ 要压缩的文件路径
+ 压缩程度,范围0-9,数值越大,压缩程序越高
+ 输出zip文件路径
+
+