Skip to content

Commit

Permalink
s3 support multiple cloud providers: hackmdio#1761
Browse files Browse the repository at this point in the history
  • Loading branch information
blademainer committed May 6, 2022
1 parent ce1b1cc commit d4bed6d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/imageRouter/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ exports.uploadImage = function (imagePath, callback) {
const command = new PutObjectCommand(params)

s3.send(command).then(data => {
let s3Endpoint = 's3.amazonaws.com'
// default settings to https scheme
let s3Endpoint = 'https://s3.amazonaws.com'
if (config.s3.region && config.s3.region !== 'us-east-1') {
s3Endpoint = `s3-${config.s3.region}.amazonaws.com`
}
// rewrite endpoint from config
if (config.s3.endpoint) {
s3Endpoint = config.s3.endpoint
} else if (config.s3.region && config.s3.region !== 'us-east-1') {
s3Endpoint = `s3-${config.s3.region}.amazonaws.com`
}
callback(null, `https://${s3Endpoint}/${config.s3bucket}/${params.Key}`)
callback(null, `${s3Endpoint}/${config.s3bucket}/${params.Key}`)
}).catch(err => {
if (err) {
callback(new Error(err), null)
Expand Down

0 comments on commit d4bed6d

Please sign in to comment.