✓ Solved

How to convert a bucket into the static website?

Hey I just followed these steps but somehow the end url is not rendering the index html instead it just download the file.

cb = client.create_bucket(Bucket=blog_name, ACL="public-read")
fileobj_response = client.upload_fileobj(
    io.BytesIO(index.encode()), Bucket=blog_name, Key="index.html"
)
object_acl_response = client.put_object_acl(
    ACL="public-read", Bucket=blog_name, Key="index.html"
)

And then I visited this page blog_name.ap-south-1.linodeobjects.com and also blog_name.website-ap-south-1.linodeobjects.com but when I entered these URL into the browser URL field it just download the website instead of rendering it.

Can someone explain what is going on here?

1 Reply

✓ Best Answer

I am closing this issue because I found the answer. The trick is to set the content type to the file when it's uploading.

    client.upload_fileobj(
        io.BytesIO(index.encode()),
        Bucket=name,
        Key="index.html",
        ExtraArgs={"ContentType": "application/json", "ACL": "public-read"},
    )

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct