Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d54b71badb | ||
|
|
ddeb2948b7 | ||
|
|
fb1ce7d931 | ||
|
|
c117d9ef1f |
+5
-1
@@ -112,7 +112,11 @@ namespace YYApi
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseYYUpload(this IApplicationBuilder builder)
|
||||
{
|
||||
return builder.UseStaticFiles();
|
||||
return builder.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
DefaultContentType = "application/x-msdownload",
|
||||
ServeUnknownFileTypes = true
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+25
-4
@@ -33,6 +33,12 @@ namespace YYApi.Helpers
|
||||
Env = env;
|
||||
}
|
||||
|
||||
public class YYUploadInfo
|
||||
{
|
||||
public string Path { get; set; }
|
||||
public int Size { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存base64文件,如果有标头按照标头自动识别
|
||||
/// </summary>
|
||||
@@ -41,7 +47,7 @@ namespace YYApi.Helpers
|
||||
/// <param name="path">存放路径</param>
|
||||
/// <param name="fileName">文件名</param>
|
||||
/// <returns></returns>
|
||||
public string SaveFile(string base64, string ext = null, string path = null, string fileName = null)
|
||||
public YYUploadInfo SaveFile(string base64, string ext = null, string path = null, string fileName = null)
|
||||
{
|
||||
byte[] bt;
|
||||
var filePath = FilePath + path;
|
||||
@@ -68,15 +74,30 @@ namespace YYApi.Helpers
|
||||
{
|
||||
bt = Convert.FromBase64String(base64);
|
||||
}
|
||||
var fn = fileName + (string.IsNullOrEmpty(ext) ? string.Empty : $".{ext}");
|
||||
return WriteFile(filePath, fn, bt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 把数据写入文件
|
||||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
return filePath + fn;
|
||||
File.WriteAllBytes(realPath + fileName, data);
|
||||
return new YYUploadInfo
|
||||
{
|
||||
Path = filePath + fileName,
|
||||
Size = data.Length
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@
|
||||
<Folder Include="Exceptions\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.1.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.1.0" />
|
||||
<PackageReference Include="HangFire.Core" Version="1.7.9" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.9" />
|
||||
<PackageReference Include="Hangfire.Console" Version="1.4.2" />
|
||||
|
||||
Reference in New Issue
Block a user