* udated to .net6 * used the .net6 version RC2 * added editconfig. * App core new Scoped Namespaces style. * BlazorAdmin new Scoped Namespaces style. * Blazor Shared new Scoped Namespaces style. * Infra new Scoped Namespaces style. * public api new Scoped Namespaces style. * web new Scoped Namespaces style. * FunctionalTests new Scoped Namespaces style. * Integrational tests new Scoped Namespaces style. * unit tests new Scoped Namespaces style. * update github action. * update github action. * change the global.
25 lines
860 B
C#
25 lines
860 B
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace Microsoft.eShopWeb.PublicApi;
|
|
|
|
public static class ImageValidators
|
|
{
|
|
private const int ImageMaximumBytes = 512000;
|
|
|
|
public static bool IsValidImage(this byte[] postedFile, string fileName)
|
|
{
|
|
return postedFile != null && postedFile.Length > 0 && postedFile.Length <= ImageMaximumBytes && IsExtensionValid(fileName);
|
|
}
|
|
|
|
private static bool IsExtensionValid(string fileName)
|
|
{
|
|
var extension = Path.GetExtension(fileName);
|
|
|
|
return string.Equals(extension, ".jpg", StringComparison.OrdinalIgnoreCase) ||
|
|
string.Equals(extension, ".png", StringComparison.OrdinalIgnoreCase) ||
|
|
string.Equals(extension, ".gif", StringComparison.OrdinalIgnoreCase) ||
|
|
string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
}
|