Here is my concern:
I am downloading a webpage and then I am writing to a file named thisArticle.html
var file = fs.createWriteStream("thisArticle.html"); var request = http.get(req.body.url, function (response) { response.pipe(file); });
After that I am trying to read file and uploading to S3, here is the code that I wrote:
fs.readFile('thisArticle.html', 'utf8', function(err, html){
if (err) {
console.log(err + "");
throw err;
}
var pathToSave = 'articles/ ' + req.body.title +'.html';
var s3bucket = new AWS.S3({ params: { Bucket: 'all-articles' } });
s3bucket.createBucket(function () {
var params = {
Key: pathToSave,
Body: html,
ACL: 'public-read'
};
s3bucket.upload(params, function (err, data) {
fs.unlink("thisArticle.html", function (err) {
console.error(err);
});
if (err) {
console.log('ERROR MSG: ', err);
res.status(500).send(err);
} else {
console.log(data.Location);
}
// ..., more code below
});
});
});
Now, I am facing two issues:
Any guides if I am missing something ?
Atul Sharma
Full Stack Developer | Cloud Native Applications
Show the URL.
s3browser.com/features-content-mime-types-editor.…
Just go to the file and remove
Content-Disposition: attachmentheader and you are all set to serve html file.Its always better to set content-type externally while uploading the file. For html files set
Content-type:text/htmlto avoid such problems.