# Minio Troubleshooting Guide This document outlines the fixes implemented for the mission file upload issues with Minio. ## Problem Description Mission uploads (logo and attachments) were not working correctly: - Files weren't appearing in Minio despite upload attempts - Mission logos weren't displaying even though they were uploaded - Participation field showed "Non spécifié" despite values in the database - SDG/ODD icons weren't displaying correctly ## Implemented Fixes ### 1. Added URL Generation Function Added a `getPublicUrl` function in `lib/s3.ts` that properly constructs URLs for files stored in Minio: ```typescript export function getPublicUrl(filePath: string): string { if (!filePath) return ''; if (filePath.startsWith('http')) return filePath; // Already a full URL // Remove leading slash if present const cleanPath = filePath.startsWith('/') ? filePath.substring(1) : filePath; // Construct the full URL const endpoint = S3_CONFIG.endpoint?.replace(/\/$/, ''); // Remove trailing slash if present const bucket = S3_CONFIG.bucket; // Return original path if no endpoint is configured if (!endpoint) return cleanPath; // Construct and return the full URL return `${endpoint}/${bucket}/${cleanPath}`; } ``` ### 2. Updated Mission Display Page Modified `app/missions/page.tsx` to use the `getPublicUrl` function when displaying mission logos: ```tsx {mission.logo ? ( {mission.name} { // Error handling... }} /> ) : null} ``` ### 3. Enhanced Upload API Updated `/app/api/missions/upload/route.ts` to: - Include additional logging - Generate and return proper public URLs - Improve error handling ### 4. Enhanced Mission Detail API Modified `/app/api/missions/[missionId]/route.ts` to include public URLs in the response: ```typescript const missionWithUrls = { ...mission, logoUrl: mission.logo ? getPublicUrl(mission.logo) : null, attachments: mission.attachments.map((attachment) => ({ ...attachment, publicUrl: getPublicUrl(attachment.filePath) })) }; ``` ### 5. Added Testing Tools 1. Browser Console Utilities: - `window.testMinioConnection()` - Test Minio connectivity - `window.getMinioUrl(path)` - Generate a public URL for debugging 2. Server-side Test Script: - Created `scripts/test-minio-upload.js` to test uploads from the command line - Tests uploading, downloading, and URL generation ## How to Test 1. **Using the browser console:** ```javascript // Test connection and list files window.testMinioConnection() // Generate URL for a specific path window.getMinioUrl('user-123/missions/456/logo.jpg') ``` 2. **Using the server-side script:** ```bash node scripts/test-minio-upload.js ``` ## Required Environment Variables Make sure these are properly set in your environment: - `MINIO_S3_UPLOAD_BUCKET_URL` - The Minio endpoint URL - `MINIO_AWS_REGION` - The AWS region (often 'us-east-1' for Minio) - `MINIO_AWS_S3_UPLOAD_BUCKET_NAME` - The bucket name - `MINIO_ACCESS_KEY` - Access key for Minio - `MINIO_SECRET_KEY` - Secret key for Minio ## Additional Notes 1. The same Minio bucket is used for both Pages and Missions. 2. Pages functionality is working properly, suggesting the Minio configuration itself is correct. 3. Make sure that the bucket has proper permissions for public read access. 4. The URL paths for SDG/ODD icons were corrected to use `/F SDG Icons 2019 WEB/F-WEB-Goal-XX.png`