|
@ -41,7 +41,9 @@ const endorserApiUrl = process.env.ENDORSER_API_URL || 'https://test-api.endorse |
|
|
|
|
|
|
|
|
// Configure AWS
|
|
|
// Configure AWS
|
|
|
const s3Client = new S3Client({ |
|
|
const s3Client = new S3Client({ |
|
|
|
|
|
endpoint: 'https://' + process.env.AWS_ENDPOINT_SERVER, |
|
|
region: process.env.AWS_REGION, |
|
|
region: process.env.AWS_REGION, |
|
|
|
|
|
forcePathStyle: true, |
|
|
credentials: { |
|
|
credentials: { |
|
|
accessKeyId: process.env.AWS_ACCESS_KEY, |
|
|
accessKeyId: process.env.AWS_ACCESS_KEY, |
|
|
secretAccessKey: process.env.AWS_SECRET_KEY |
|
|
secretAccessKey: process.env.AWS_SECRET_KEY |
|
@ -209,6 +211,9 @@ app.post('/image', uploadMulter.single('image'), async (req, res) => { |
|
|
ContentType: reqFile.mimetype, // File content type
|
|
|
ContentType: reqFile.mimetype, // File content type
|
|
|
Key: fileName, // File name to use in S3
|
|
|
Key: fileName, // File name to use in S3
|
|
|
}; |
|
|
}; |
|
|
|
|
|
if (process.env.S3_SET_ACL === 'true') { |
|
|
|
|
|
params.ACL = 'public-read'; |
|
|
|
|
|
} |
|
|
const command = new PutObjectCommand(params); |
|
|
const command = new PutObjectCommand(params); |
|
|
const response = await s3Client.send(command); |
|
|
const response = await s3Client.send(command); |
|
|
if (response.$metadata.httpStatusCode !== 200) { |
|
|
if (response.$metadata.httpStatusCode !== 200) { |
|
@ -224,6 +229,8 @@ app.post('/image', uploadMulter.single('image'), async (req, res) => { |
|
|
console.error("Error deleting temp file", reqFile.path, "with error (but continuing):", err); |
|
|
console.error("Error deleting temp file", reqFile.path, "with error (but continuing):", err); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
// AWS URL: https://gifts-image-test.s3.amazonaws.com/gifts-image-test/FILE
|
|
|
|
|
|
// American Cloud URL: https://a2-west.americancloud.com/TENANT:giftsimagetest/FILE
|
|
|
return res.status(200).send(JSON.stringify({success: true, url: finalUrl})); |
|
|
return res.status(200).send(JSON.stringify({success: true, url: finalUrl})); |
|
|
} |
|
|
} |
|
|
} catch (uploadError) { |
|
|
} catch (uploadError) { |
|
|