Amazon S3 downloads index.html instead of serving
Solution 1:
Running curl -I against the url you posted gives the following result:
curl -I http://speakeasylinguistics.com.s3-website-us-east-1.amazonaws.com/
HTTP/1.1 200 OK
x-amz-id-2: DmfUpbglWQ/evhF3pTiXYf6c+gIE8j0F6mw7VmATOpfc29V5tb5YTeojC68jE7Rd
x-amz-request-id: E233603809AF9956
Date: Sun, 18 Aug 2013 07:58:55 GMT
Content-Disposition: attachment
Last-Modified: Sun, 18 Aug 2013 07:05:20 GMT
ETag: "eacded76ceb4831aaeae2805c892fa1c"
Content-Type: text/html
Content-Length: 2585
Server: AmazonS3
This line is the culprit:
Content-Disposition: attachment
If you are using the AWS console, I believe this can be changed by selecting the file in S3 and modifying its meta data by removing this property.
Solution 2:
If you are using Hashicorp Terraform you can specify the content-type
on an aws_s3_bucket_object as follows
resource "aws_s3_bucket_object" "index" {
bucket = "yourbucketnamehere"
key = "index.html"
content = "<h1>Hello, world</h1>"
content_type = "text/html"
}
This should serve your content appropriately in the browser.
Solution 3:
If you are doing this programmatically you can set the ContentType
and/or ContentDisposition
params in your upload.
[PHP Example]
$output = $s3->putObject(array(
'Bucket' => $bucket,
'Key' => md5($share). '.html',
'ContentType' => 'text/html',
'Body' => $share,
));
putObject Docs
Solution 4:
if you guys are trying to upload it with Boto3 and python 3.7 or above try with
s3 = boto3.client('s3')
S3.upload_file(local_file,bucket,S3_file,ExtraArgs={'ContentType':'text/html'})
for update Content-Type
Solution 5:
For anyone else facing this issue, there's a typo in the URL you can find under Properties > Static website hosting
. For instance, the URL provided is
http://{bucket}.s3-website-{region}.amazonaws.com
but it should be
http://{bucket}.s3-website.{region}.amazonaws.com
Note the .
between website
and region
.