fix: preserve original file type on upload — never convert PNG to JPG
Problem: cropper always called out.toBlob(..., 'image/jpeg') regardless of the original file type, silently converting PNGs to JPGs. Fix: - openCropper() now stores file.type and file.name on the cropper object - applyCrop() uses the stored mime type for toBlob() and the filename - Quality param only passed for lossy formats (jpeg/webp), not for PNG/GIF - uploadImage() accept list expanded: svg, ico allowed - Server-side: .svg and .ico added to allowed extensions Result: PNG stays PNG, WebP stays WebP, ICO stays ICO. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -589,7 +589,7 @@ app.MapPost("/api/upload", async (HttpRequest request, IWebHostEnvironment env)
|
||||
if (!request.HasFormContentType || !request.Form.Files.Any())
|
||||
return Results.BadRequest("No file provided.");
|
||||
var file = request.Form.Files[0];
|
||||
var allowed = new[] { ".jpg", ".jpeg", ".png", ".webp", ".gif" };
|
||||
var allowed = new[] { ".jpg", ".jpeg", ".png", ".webp", ".gif", ".svg", ".ico" };
|
||||
var ext = Path.GetExtension(file.FileName).ToLowerInvariant();
|
||||
if (!allowed.Contains(ext)) return Results.BadRequest("File type not allowed.");
|
||||
var uploadsDir = Path.Combine(env.WebRootPath, "uploads");
|
||||
|
||||
Reference in New Issue
Block a user