File tree Expand file tree Collapse file tree
src/Modules/SimplCommerce.Module.StorageLocal Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments