I've written code that creates multiple HTML files. I am trying to upload these files directly to an S3 bucket directory without saving the files locally. How can this be done?
I've been saving the files locally with fs.writeFileSync(directory + title + '.html', data);
and I imagine that I'll have to do something along the lines of passing data
into an fs
stream, but I don't know where to start.
If anyone could help and point me in the right direction, I would appreciate it very much. Thank you!
Edit: Even when I try to upload an html file generated from my code and saved locally, it seems to not even attempt to upload the file. This is the upload section of my code:
s3.upload(bucket, function(err, data){
if(err) {
console.log("Error: ", err);
} else {
console.log("Success: ", data.Location);
}
});
However it doesn't print an error or success message. Why is that?
Edit 2: Here's the gist of what I'm doing:
let aws = require('aws-sdk');
aws.config.update({
//Removed the strings for security reasons
accessKeyId: '*******',
secretAccessKey: '********'
});
let s3 = new aws.S3({
apiVersion: "2006-03-01",
});
//This lists all the buckets. It works correctly!
s3.listBuckets(function(err, data){
if(err){
console.log("Error: ", error);
} else {
console.log("Success: ", data.Buckets);
}
});
//This is where my program creates the HTML file.
//It concatenates various strings into one large string creating the entirety of the HTML file in one string variable called "data".
s3.upload({
Bucket: 'reporting',
Key: s3Folder + platformPath + '/' + browserPath + '/' + title + '.html',
Body: data
}, function (err, data) {
if (err) {
console.log("Error: ", err);
} if (data) {
console.log("Success: ", data.Location);
}
});
//When run, the program seems to not even enter the 's3.upload()' function.
//It doesn't return an error or success message.