fix #1049 Make sure the directory exists before writing to the file.

pull/1050/head
maliming 6 years ago
parent e896b96758
commit 41bfc39228

@ -23,6 +23,17 @@ namespace Volo.Blogging.Files
{
Check.NotNullOrWhiteSpace(name, nameof(name));
if (!Directory.Exists(Options.FileUploadLocalFolder))
{
Directory.CreateDirectory(Options.FileUploadLocalFolder);
return Task.FromResult(
new RawFileDto
{
Bytes = new byte[0]
}
);
}
var filePath = Path.Combine(Options.FileUploadLocalFolder, name);
return Task.FromResult(
@ -53,6 +64,11 @@ namespace Volo.Blogging.Files
var uniqueFileName = GenerateUniqueFileName(Path.GetExtension(input.Name));
var filePath = Path.Combine(Options.FileUploadLocalFolder, uniqueFileName);
if (!Directory.Exists(Options.FileUploadLocalFolder))
{
Directory.CreateDirectory(Options.FileUploadLocalFolder);
}
File.WriteAllBytes(filePath, input.Bytes); //TODO: Previously was using WriteAllBytesAsync, but it's only in .netcore.
return Task.FromResult(new FileUploadOutputDto

Loading…
Cancel
Save