fullstackhero / blazor-starter-kit

Clean Architecture Template for Blazor WebAssembly Built with MudBlazor Components.
MIT License
3.45k stars 726 forks source link

Is Docker still in Mind (ProfilePictures not working) #342

Closed chrisgate closed 2 years ago

chrisgate commented 2 years ago

in development everything is ok but in docker the folder are create like : Files --Images\ProfilePictures --1412cb20-cd01-41f3-bf26-4909db61614a-182989ef-9030-44ac-95dd-9d14249a8cde.jpg where on development using windows it will be: Files --Images --ProfilePictures -- 1412cb20-cd01-41f3-bf26-4909db61614a-182989ef-9030-44ac-95dd-9d14249a8cde.jpg Is this bug or i have done some wrong?

neozhu commented 2 years ago

maybe this file path format is different in Linux and windows

chrisgate commented 2 years ago

true @neozhu Again linux docker doesn't respect "Files\Images\ProfilePictures" to create folder tree like: --File --Images --ProfilePictures it will just create create one folder name with "Files\Images\ProfilePictures", i think that is the issue there.

Cheers

mikecasas commented 2 years ago

May have to rethink the hard coded path and use System.IO.Path.DirectorySeparatorChar

https://github.com/blazorhero/CleanArchitecture/blob/ffcfed186a2b820a29a104db51161767f8d41bbe/src/Application/Enums/UploadType.cs#L10-L11

chrisgate commented 2 years ago

thanks @mikecasas can u give possible way of using System.IO.Path.DirectorySeparatorChar?

Thanks

mikecasas commented 2 years ago

@chrisgate Basically something like the below. I haven't dug into this repo too much, but I have come across this issue working with other projects.

SomePath = "Images" + DirectorySeparatorChar + "ProfilePictures"
chrisgate commented 2 years ago

@mikecasas you mentioning this (System.IO.Path.DirectorySeparatorChar) really helped me in digging deep. anyways,this extension does the job:

`private const char WinSeparator = '\'; private const char UnixSeparator = '/'; public static string NormalizePath(this string path) { if (string.IsNullOrEmpty(path)) return path;

        if (Path.DirectorySeparatorChar == WinSeparator)
            path = path.Replace(UnixSeparator, WinSeparator);
        if (Path.DirectorySeparatorChar == UnixSeparator)
            path = path.Replace(WinSeparator, UnixSeparator);

        return path.Replace(string.Concat(WinSeparator, WinSeparator), WinSeparator.ToString());
}`

Thanks and Cheers!

mikecasas commented 2 years ago

Glad I can help. I'm not sure if you even need that logic. I think the framework knows what it is running on and "converts" the character.

https://docs.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=net-5.0

chrisgate commented 2 years ago

I think that logic is needed as seem below: https://github.com/blazorhero/CleanArchitecture/blob/637517163f1e7f40b6be0952f8cf4ab690d759e0/src/Infrastructure/Services/UploadService.cs#L18 All these Path.Combine changes the behavior based on platform u are running it.