Skip to content Skip to sidebar Skip to footer

Upload HTML File To AWS S3 And Then Serving It Instead Of Downloading

I am downloading a web page and then I am writing to a file named thisArticle.html, using the below code. var file = fs.createWriteStream('thisArticle.html'); var request = http.g

Solution 1:

Set the ContentType to "text/html".

s3 = boto3.client("s3")
s3.put_object(
        Bucket=s3_bucket,
        Key=s3_key,
        Body=html_string,
        CacheControl="max-age=0,no-cache,no-store,must-revalidate",
        ContentType="text/html",
        ACL="public-read"
    )

Solution 2:

It looks like your upload function is deleting the file with fs.unlink before it gets uploaded. That's why its going up as 0 Bytes.

Also, to make the bucket serve the HTML, you need to turn on webserving as described in the AWS S3 Docs. http://docs.aws.amazon.com/AmazonS3/latest/UG/ConfiguringBucketWebsite.html


Post a Comment for "Upload HTML File To AWS S3 And Then Serving It Instead Of Downloading"