diff --git a/backend/handlers/portfolio/images.go b/backend/handlers/portfolio/images.go index 7264091..d1db1f4 100644 --- a/backend/handlers/portfolio/images.go +++ b/backend/handlers/portfolio/images.go @@ -556,7 +556,7 @@ func UploadImage(w http.ResponseWriter, r *http.Request) { } defer file.Close() - thumbFile, _, err := r.FormFile("thumbnail") + thumbFile, thumbHeader, err := r.FormFile("thumbnail") if err != nil { log.Printf("Failed to get thumbnail: %v", err) http.Error(w, "No thumbnail provided", http.StatusBadRequest) @@ -575,13 +575,21 @@ func UploadImage(w http.ResponseWriter, r *http.Request) { // Use nanosecond timestamp for unique keys timestamp := time.Now().UnixNano() - ext := ".jpg" + + // Extract extension from main file + mainExt := ".jpg" if idx := strings.LastIndex(header.Filename, "."); idx != -1 { - ext = strings.ToLower(header.Filename[idx:]) + mainExt = strings.ToLower(header.Filename[idx:]) } - key := fmt.Sprintf("portfolio/%d%s", timestamp, ext) - thumbKey := fmt.Sprintf("portfolio/%d_thumb%s", timestamp, ext) + // Extract extension from thumbnail file + thumbExt := ".jpg" + if idx := strings.LastIndex(thumbHeader.Filename, "."); idx != -1 { + thumbExt = strings.ToLower(thumbHeader.Filename[idx:]) + } + + key := fmt.Sprintf("portfolio/%d%s", timestamp, mainExt) + thumbKey := fmt.Sprintf("portfolio/%d_thumb%s", timestamp, thumbExt) fileBytes, err := io.ReadAll(file) if err != nil { @@ -589,14 +597,8 @@ func UploadImage(w http.ResponseWriter, r *http.Request) { http.Error(w, "Failed to read file", http.StatusInternalServerError) return } - - // Strip metadata (EXIF, GPS, camera info) and auto-orient - fileBytes, err = processImage(fileBytes, 85) - if err != nil { - log.Printf("Failed to process image: %v", err) - http.Error(w, "Failed to process image", http.StatusInternalServerError) - return - } + // Images are already processed by frontend (compressed, metadata stripped) + // Skip re-encoding - just use the uploaded bytes directly thumbBytes, err := io.ReadAll(thumbFile) if err != nil { @@ -605,13 +607,7 @@ func UploadImage(w http.ResponseWriter, r *http.Request) { return } - // Strip metadata from thumbnail too - thumbBytes, err = processImage(thumbBytes, 75) - if err != nil { - log.Printf("Failed to process thumbnail: %v", err) - http.Error(w, "Failed to process thumbnail", http.StatusInternalServerError) - return - } + // Thumbnail is already processed by frontend - use as-is bucket := "crussell"