Skip to content

Commit 30e60e7

Browse files
onetarunhishamco
authored andcommitted
Modification in LocalStorageService
1 parent 28c3c85 commit 30e60e7

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

src/Modules/SimplCommerce.Module.StorageLocal/LocalStorageService.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,29 @@ public string GetMediaUrl(string fileName)
1616

1717
public async Task SaveMediaAsync(Stream mediaBinaryStream, string fileName, string mimeType = null)
1818
{
19-
var filePath = Path.Combine(GlobalConfiguration.WebRootPath, MediaRootFoler, fileName);
19+
var dirPath = Path.Combine(GlobalConfiguration.WebRootPath, MediaRootFoler);
20+
if (!Directory.Exists(dirPath))
21+
{
22+
Directory.CreateDirectory(dirPath);
23+
}
24+
var filePath = Path.Combine(dirPath, fileName);
2025
using (var output = new FileStream(filePath, FileMode.Create))
2126
{
2227
await mediaBinaryStream.CopyToAsync(output);
28+
2329
}
2430
}
2531

2632
public async Task DeleteMediaAsync(string fileName)
2733
{
28-
var filePath = Path.Combine(GlobalConfiguration.WebRootPath, MediaRootFoler, fileName);
29-
if (File.Exists(filePath))
34+
if (!string.IsNullOrEmpty(fileName))
3035
{
31-
await Task.Run(() => File.Delete(filePath));
36+
37+
var filePath = Path.Combine(GlobalConfiguration.WebRootPath, MediaRootFoler, fileName);
38+
if (File.Exists(filePath))
39+
{
40+
await Task.Run(() => File.Delete(filePath));
41+
}
3242
}
3343
}
3444
}

0 commit comments

Comments
 (0)