missions s3

This commit is contained in:
alma 2025-05-06 12:46:06 +02:00
parent bf2e12b877
commit d07f48394a
2 changed files with 78 additions and 3 deletions

View File

@ -437,7 +437,20 @@ export function MissionsAdminPanel() {
}); });
if (!logoResponse.ok) { if (!logoResponse.ok) {
console.error('Failed to upload logo:', await logoResponse.json()); console.error('Failed to upload logo - Status:', logoResponse.status, logoResponse.statusText);
try {
const errorJson = await logoResponse.json().catch(() => null);
if (errorJson) {
console.error('Error details:', errorJson);
} else {
console.error('No JSON error details available - Response may be empty');
// Try to get error details from headers
const headers = Object.fromEntries(logoResponse.headers.entries());
console.error('Response headers:', headers);
}
} catch (parseError) {
console.error('Error parsing response:', parseError);
}
// Continue with mission creation even if logo upload fails // Continue with mission creation even if logo upload fails
} else { } else {
console.log('Logo uploaded successfully'); console.log('Logo uploaded successfully');
@ -461,7 +474,20 @@ export function MissionsAdminPanel() {
}); });
if (!attachmentResponse.ok) { if (!attachmentResponse.ok) {
console.error(`Failed to upload attachment ${file.name}:`, await attachmentResponse.json()); console.error(`Failed to upload attachment ${file.name} - Status:`, attachmentResponse.status, attachmentResponse.statusText);
try {
const errorJson = await attachmentResponse.json().catch(() => null);
if (errorJson) {
console.error('Error details:', errorJson);
} else {
console.error('No JSON error details available - Response may be empty');
// Try to get error details from headers
const headers = Object.fromEntries(attachmentResponse.headers.entries());
console.error('Response headers:', headers);
}
} catch (parseError) {
console.error('Error parsing response:', parseError);
}
return false; return false;
} else { } else {
console.log(`Attachment ${file.name} uploaded successfully`); console.log(`Attachment ${file.name} uploaded successfully`);

View File

@ -50,19 +50,37 @@ export async function uploadMissionLogo(
hasSecretKey: !!S3_CONFIG.secretKey || 'MISSING!' hasSecretKey: !!S3_CONFIG.secretKey || 'MISSING!'
}); });
// Log the full path being used
console.log('FULL S3 PATH:', `${S3_CONFIG.endpoint}/${S3_CONFIG.missionsBucket}/${filePath}`);
const command = new PutObjectCommand({ const command = new PutObjectCommand({
Bucket: S3_CONFIG.missionsBucket, Bucket: S3_CONFIG.missionsBucket,
Key: filePath, Key: filePath,
Body: buffer, Body: buffer,
ContentType: file.type, ContentType: file.type,
// Add ACL for public read access
ACL: 'public-read',
}); });
console.log('Sending upload command to S3/Minio...'); console.log('Sending upload command to S3/Minio...');
console.log('Command details:', {
Bucket: command.input.Bucket,
Key: command.input.Key,
ContentType: command.input.ContentType,
ACL: command.input.ACL,
ContentLength: buffer.length
});
try { try {
const result = await s3Client.send(command); const result = await s3Client.send(command);
console.log('Upload successful, result:', result); console.log('Upload successful, result:', result);
} catch (uploadError) { } catch (uploadError) {
console.error('S3 upload error details:', uploadError); console.error('S3 upload error details:', uploadError);
console.error('Error name:', (uploadError as any).name);
console.error('Error message:', (uploadError as any).message);
if ((uploadError as any).$metadata) {
console.error('Error metadata:', (uploadError as any).$metadata);
}
throw uploadError; throw uploadError;
} }
@ -86,12 +104,21 @@ export async function uploadMissionAttachment(
fileSize: number fileSize: number
}> { }> {
try { try {
console.log('=== Starting attachment upload process ===');
console.log('Upload params:', { userId, missionId, fileName: file.name, fileSize: file.size, fileType: file.type });
// Create file path // Create file path
const filePath = getMissionAttachmentPath(userId, missionId, file.name); const filePath = getMissionAttachmentPath(userId, missionId, file.name);
console.log('Generated file path:', filePath);
// Convert file to ArrayBuffer // Convert file to ArrayBuffer
console.log('Converting file to buffer...');
const arrayBuffer = await file.arrayBuffer(); const arrayBuffer = await file.arrayBuffer();
const buffer = Buffer.from(arrayBuffer); const buffer = Buffer.from(arrayBuffer);
console.log('Buffer created, size:', buffer.length);
// Log the full path being used
console.log('FULL S3 PATH:', `${S3_CONFIG.endpoint}/${S3_CONFIG.missionsBucket}/${filePath}`);
// Upload to Minio using missions bucket // Upload to Minio using missions bucket
const command = new PutObjectCommand({ const command = new PutObjectCommand({
@ -99,9 +126,31 @@ export async function uploadMissionAttachment(
Key: filePath, Key: filePath,
Body: buffer, Body: buffer,
ContentType: file.type, ContentType: file.type,
// Add ACL for public read access
ACL: 'public-read',
}); });
await s3Client.send(command); console.log('Sending upload command to S3/Minio...');
console.log('Command details:', {
Bucket: command.input.Bucket,
Key: command.input.Key,
ContentType: command.input.ContentType,
ACL: command.input.ACL,
ContentLength: buffer.length
});
try {
const result = await s3Client.send(command);
console.log('Upload successful, result:', result);
} catch (uploadError) {
console.error('S3 upload error details:', uploadError);
console.error('Error name:', (uploadError as any).name);
console.error('Error message:', (uploadError as any).message);
if ((uploadError as any).$metadata) {
console.error('Error metadata:', (uploadError as any).$metadata);
}
throw uploadError;
}
return { return {
filename: file.name, filename: file.name,