3.5 KiB
3.5 KiB
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:
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:
{mission.logo ? (
<img
src={mission.logo ? getPublicUrl(mission.logo) : ''}
alt={mission.name}
className="w-full h-full object-cover rounded-md border border-gray-200"
onError={(e) => {
// 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:
const missionWithUrls = {
...mission,
logoUrl: mission.logo ? getPublicUrl(mission.logo) : null,
attachments: mission.attachments.map((attachment) => ({
...attachment,
publicUrl: getPublicUrl(attachment.filePath)
}))
};
5. Added Testing Tools
-
Browser Console Utilities:
window.testMinioConnection()- Test Minio connectivitywindow.getMinioUrl(path)- Generate a public URL for debugging
-
Server-side Test Script:
- Created
scripts/test-minio-upload.jsto test uploads from the command line - Tests uploading, downloading, and URL generation
- Created
How to Test
-
Using the browser console:
// Test connection and list files window.testMinioConnection() // Generate URL for a specific path window.getMinioUrl('user-123/missions/456/logo.jpg') -
Using the server-side script:
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 URLMINIO_AWS_REGION- The AWS region (often 'us-east-1' for Minio)MINIO_AWS_S3_UPLOAD_BUCKET_NAME- The bucket nameMINIO_ACCESS_KEY- Access key for MinioMINIO_SECRET_KEY- Secret key for Minio
Additional Notes
- The same Minio bucket is used for both Pages and Missions.
- Pages functionality is working properly, suggesting the Minio configuration itself is correct.
- Make sure that the bucket has proper permissions for public read access.
- The URL paths for SDG/ODD icons were corrected to use
/F SDG Icons 2019 WEB/F-WEB-Goal-XX.png