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) {
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
} else {
console.log('Logo uploaded successfully');
@ -461,7 +474,20 @@ export function MissionsAdminPanel() {
});
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;
} else {
console.log(`Attachment ${file.name} uploaded successfully`);

View File

@ -50,19 +50,37 @@ export async function uploadMissionLogo(
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({
Bucket: S3_CONFIG.missionsBucket,
Key: filePath,
Body: buffer,
ContentType: file.type,
// Add ACL for public read access
ACL: 'public-read',
});
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;
}
@ -86,12 +104,21 @@ export async function uploadMissionAttachment(
fileSize: number
}> {
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
const filePath = getMissionAttachmentPath(userId, missionId, file.name);
console.log('Generated file path:', filePath);
// Convert file to ArrayBuffer
console.log('Converting file to buffer...');
const arrayBuffer = await file.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
const command = new PutObjectCommand({
@ -99,9 +126,31 @@ export async function uploadMissionAttachment(
Key: filePath,
Body: buffer,
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 {
filename: file.name,