10/23更新

This commit is contained in:
橙子
2022-10-23 22:29:35 +08:00
parent 16d25fb60d
commit 5da2143212
8 changed files with 54 additions and 18 deletions

View File

@@ -134,20 +134,35 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{ {
await f.CopyToAsync(stream); await f.CopyToAsync(stream);
//如果是图片类型,还需要生成缩略图 //如果是图片类型,还需要生成缩略图,当然,如果图片很小,直接复制过去即可
if (PathEnum.Image.ToString().Equals(type)) if (PathEnum.Image.ToString().Equals(type))
{ {
//保存至缩略图路径
var result = _thumbnailSharpInvoer.CreateThumbnailBytes(thumbnailSize: 300,
imageStream: stream,
imageFormat: Format.Jpeg);
string thumbnailPath = $"{PathConst.wwwroot}/{PathEnum.Thumbnail}"; string thumbnailPath = $"{PathConst.wwwroot}/{PathEnum.Thumbnail}";
if (!Directory.Exists(thumbnailPath)) if (!Directory.Exists(thumbnailPath))
{ {
Directory.CreateDirectory(thumbnailPath); Directory.CreateDirectory(thumbnailPath);
} }
//保存至缩略图路径
byte[] result=null!;
try
{
result = _thumbnailSharpInvoer.CreateThumbnailBytes(thumbnailSize: 300,
imageStream: stream,
imageFormat: Format.Jpeg);
}
catch
{
result = new byte[stream.Length];
stream.Read(result, 0, result.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
}
finally
{
await System.IO.File.WriteAllBytesAsync(Path.Combine(thumbnailPath, filename), result); await System.IO.File.WriteAllBytesAsync(Path.Combine(thumbnailPath, filename), result);
} }
}
}; };
@@ -185,10 +200,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{ {
Directory.CreateDirectory(typePath); Directory.CreateDirectory(typePath);
} }
using (var stream = new FileStream(Path.Combine(typePath, filename), FileMode.Open, FileAccess.ReadWrite)) using (var stream = new FileStream(Path.Combine(typePath, filename), FileMode.Open, FileAccess.ReadWrite))
{ {
byte[] result=null!;
try
{
//保存至缩略图路径 //保存至缩略图路径
var result = _thumbnailSharpInvoer.CreateThumbnailBytes(thumbnailSize: 300, result = _thumbnailSharpInvoer.CreateThumbnailBytes(thumbnailSize: 300,
imageStream: stream, imageStream: stream,
imageFormat: Format.Jpeg); imageFormat: Format.Jpeg);
@@ -196,8 +217,23 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{ {
Directory.CreateDirectory(thumbnailPath); Directory.CreateDirectory(thumbnailPath);
} }
}
catch
{
result = new byte[stream.Length];
stream.Read(result, 0, result.Length);
// 设置当前流的位置为流的开始
stream.Seek(0, SeekOrigin.Begin);
////如果当前文件同步失败,就跳转到下一个
}
finally {
await System.IO.File.WriteAllBytesAsync(Path.Combine(thumbnailPath, filename), result); await System.IO.File.WriteAllBytesAsync(Path.Combine(thumbnailPath, filename), result);
}; }
}
} }
return Result.Success(); return Result.Success();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.4 KiB

View File

@@ -3,7 +3,7 @@
round round
:width="width" :width="width"
:height="height" :height="height"
:src="url+(src??'0')+'/true'" :src="url+(src??'0')"
/> />
</template> </template>