0
I’m developing an application in Nodejs using the AWS SDK. Summarizing the code creates a Bucket, assigns the security policies to allow public access, and enables it to static websites however, when sending the files via SDK when accessing the website address the content is downloaded to the PC and not loaded in the browser.
Note: if the files are sent directly from the AWS console the site works correctly.
Does anyone have an idea of how I can solve this problem? I did several searches and so far I could not find the solution.
exports.createObject = (req, res) => {
return new Promise((resolve, reject) => {
const s3 = new S3Client({
region: req.body.region
})
async function run() {
try {
const indexHTML = path.resolve('exPages', 'index.html')
let fileContent = fs.readFileSync(indexHTML)
let params = {
Bucket: req.body.bucket,
Key: path.basename(indexHTML),
Body: fileContent,
}
_Display.line()
console.log(chalk.blueBright('Request - Upload files'))
_Display.line()
let data = await s3.send(new PutObjectCommand(params))
console.log(chalk.gray('Upload complete'))
console.log('')
console.log('', data)
resolve(data)
} catch (error) {
console.log('Erro', error)
reject(error)
}
}
run()
})
}
Leo, the files that are being uploaded are actually html type. I passed in Content Type "text/html" however the problem continues
– Michel Eliabe Moreira Dias
Putz, sorry. I understood that you wanted to load the Assets. I will edit the answer.
– Leo Lamas
Leo, first thanks for the help. I discovered that there was a typo in Contenttype: "text/html"
– Michel Eliabe Moreira Dias