Browse Source

ignore file not found exception (trivial)

pull/3463/head
Alper Ebicoglu 6 years ago
parent
commit
d3b139ce10
  1. 17
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Files/RawFileDto.cs
  2. 18
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Files/FileAppService.cs

17
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Files/RawFileDto.cs

@ -1,7 +1,22 @@
namespace Volo.Blogging.Files
using System.Security.Cryptography;
using Volo.Abp.Threading;
namespace Volo.Blogging.Files
{
public class RawFileDto
{
public byte[] Bytes { get; set; }
public bool IsFileEmpty => Bytes == null || Bytes.Length == 0;
public RawFileDto()
{
}
public static RawFileDto EmptyResult()
{
return new RawFileDto() {Bytes = new byte[0]};
}
}
}

18
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Files/FileAppService.cs

@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.Validation;
@ -12,9 +13,11 @@ namespace Volo.Blogging.Files
public class FileAppService : BloggingAppServiceBase, IFileAppService
{
public BlogFileOptions Options { get; }
private readonly ILogger<FileAppService> _logger;
public FileAppService(IOptions<BlogFileOptions> options)
public FileAppService(IOptions<BlogFileOptions> options, ILogger<FileAppService> logger)
{
_logger = logger;
Options = options.Value;
}
@ -35,12 +38,13 @@ namespace Volo.Blogging.Files
var filePath = Path.Combine(Options.FileUploadLocalFolder, name);
return Task.FromResult(
new RawFileDto
{
Bytes = File.ReadAllBytes(filePath)
}
);
if (File.Exists(filePath))
{
return Task.FromResult(new RawFileDto {Bytes = File.ReadAllBytes(filePath)});
}
_logger.LogError($"Cannot find the file {filePath}");
return Task.FromResult(RawFileDto.EmptyResult());
}
public virtual Task<FileUploadOutputDto> CreateAsync(FileUploadInputDto input)

Loading…
Cancel
Save