|
@@ -13,8 +13,12 @@ using System.Threading.Tasks;
|
|
|
using System.Xml;
|
|
|
using System.Xml.Linq;
|
|
|
using TEAMModelOS.SDK.Context.Configuration;
|
|
|
+using TEAMModelOS.SDK.Context.Constant;
|
|
|
+using TEAMModelOS.SDK.Context.Constant.Common;
|
|
|
using TEAMModelOS.SDK.Context.Exception;
|
|
|
+using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
|
|
|
using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
|
|
|
+using TEAMModelOS.SDK.Helper.Common.StringHelper;
|
|
|
using TEAMModelOS.SDK.Helper.Security.ShaHash;
|
|
|
using TEAMModelOS.SDK.Module.AzureBlob.Container;
|
|
|
|
|
@@ -72,9 +76,9 @@ namespace HiTeachCE.Controllers
|
|
|
[RequestSizeLimit(102_400_000_00)] //最大10000m左右
|
|
|
public async Task<BaseJosnRPCResponse> upload([FromForm] IFormFile file)
|
|
|
{
|
|
|
- if (!IsImage(file.OpenReadStream())) {
|
|
|
- throw new BizException("请上传图片类型的文件!", 2);
|
|
|
- }
|
|
|
+ //if (!IsImage(file.OpenReadStream())) {
|
|
|
+ // throw new BizException("请上传图片类型的文件!", 2);
|
|
|
+ //}
|
|
|
|
|
|
JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
|
|
|
string filname = ShaHashHelper.GetSHA1(file.OpenReadStream());
|
|
@@ -92,19 +96,38 @@ namespace HiTeachCE.Controllers
|
|
|
return responseBuilder.Data(url).build();
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- public Boolean IsImage(Stream stream)
|
|
|
+ [HttpPost("uploadBase64")]
|
|
|
+ public async Task<BaseJosnRPCResponse> BlobSaveBase64(JosnRPCRequest<string> files)
|
|
|
{
|
|
|
- try
|
|
|
+ string filname = ShaHashHelper.GetSHA1(files.@params);
|
|
|
+ JsonRPCResponseBuilder responseBuilder = new JsonRPCResponseBuilder();
|
|
|
+ string[] strs = files.@params.Split(',');
|
|
|
+ string fileExt = StringHelper.SubMidString(strs[0], ":", ";");
|
|
|
+ if (ContentTypeDict.extdict.TryGetValue(fileExt, out string ext))
|
|
|
{
|
|
|
- System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
|
|
|
- return true;
|
|
|
+ fileExt = ext;
|
|
|
}
|
|
|
- catch (Exception e)
|
|
|
+ else
|
|
|
{
|
|
|
- return false;
|
|
|
+ //解决多种扩展名不能获取的
|
|
|
+ string[] sp = StringHelper.SubMidString(strs[0], "/", ";").Split("-");
|
|
|
+ fileExt = sp[sp.Length - 1];
|
|
|
+ sp = fileExt.Split("+");
|
|
|
+ fileExt = "." + sp[sp.Length - 1];
|
|
|
}
|
|
|
+ string path = BaseConfigModel.ContentRootPath + "/Avatar/" + filname + fileExt;
|
|
|
+ if (System.IO.File.Exists(path) == false)
|
|
|
+ {
|
|
|
+ FileStream fs = new FileStream(path, FileMode.Create);
|
|
|
+ BinaryWriter bw = new BinaryWriter(fs);
|
|
|
+ bw.Write(Convert.FromBase64String(strs[1]));
|
|
|
+ bw.Close();
|
|
|
+ fs.Close();
|
|
|
+ }
|
|
|
+ var url = "https://cdhabook.teammodel.cn/avatar/" + filname + fileExt;
|
|
|
+ return responseBuilder.Data(url).build();
|
|
|
}
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// docUrl
|
|
|
/// folder
|