From d54b71badbe51ea9410bd86f88971fde4aacf088 Mon Sep 17 00:00:00 2001 From: xRain Date: Thu, 12 Mar 2020 11:46:30 +0800 Subject: [PATCH] update package; add write file --- Helpers/YYUpload.cs | 19 +++++++++++++++---- YYApi.csproj | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Helpers/YYUpload.cs b/Helpers/YYUpload.cs index bacbe99..c1ef58f 100644 --- a/Helpers/YYUpload.cs +++ b/Helpers/YYUpload.cs @@ -74,18 +74,29 @@ namespace YYApi.Helpers { bt = Convert.FromBase64String(base64); } + var fn = fileName + (string.IsNullOrEmpty(ext) ? string.Empty : $".{ext}"); + return WriteFile(filePath, fn, bt); + } + /// + /// 把数据写入文件 + /// + /// + /// + /// + /// + public YYUploadInfo WriteFile(string filePath, string fileName, byte[] data) + { var realPath = Directory.GetCurrentDirectory() + "/wwwroot" + filePath; if (!Directory.Exists(realPath)) { Directory.CreateDirectory(realPath); } - var fn = fileName + (string.IsNullOrEmpty(ext) ? string.Empty : $".{ext}"); - File.WriteAllBytes(realPath + fn, bt); + File.WriteAllBytes(realPath + fileName, data); return new YYUploadInfo { - Path = filePath + fn, - Size = bt.Length + Path = filePath + fileName, + Size = data.Length }; } } diff --git a/YYApi.csproj b/YYApi.csproj index ba88af9..f5a31d0 100644 --- a/YYApi.csproj +++ b/YYApi.csproj @@ -23,8 +23,8 @@ - - + +