upload method
Written by
Updated at October 29, 2024
Uploads a static website hosting configuration for a bucket.
For more information on getting started with the API and the general request format, see How to use the S3 API.
Request
PUT /{bucket}?website HTTP/2
Path parameters
Parameter | Description |
---|---|
bucket |
Bucket name. |
Query parameters
Parameter | Description |
---|---|
website |
Required parameter that indicates the type of operation. |
Headers
Use the appropriate common headers in your request.
Data schema
You can configure a bucket:
As a website
To redirect all requests
For conditionally redirecting requests
Configuration example:
<!--Website configuration-->
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>Error.html</Key>
</ErrorDocument>
</WebsiteConfiguration>
Possible elements:
Element | Description |
---|---|
WebsiteConfiguration |
Top-level header of the website description. |
IndexDocument/Suffix |
Home page of the website. Path: /WebsiteConfiguration/IndexDocument/Suffix . |
ErrorDocument/Key |
Document the user sees in case of 4xx errors.Path: /WebsiteConfiguration/ErrorDocument/Key . |
Configuration example:
<!--Configuration for redirecting all requests-->
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<RedirectAllRequestsTo>
<HostName>example.com</HostName>
<Protocol>http</Protocol>
</RedirectAllRequestsTo>
</WebsiteConfiguration>
Possible elements:
Element | Description |
---|---|
WebsiteConfiguration |
Top-level header of the website description. |
RedirectAllRequestsTo |
Contains configuration for redirecting all requests. Path: /WebsiteConfiguration/RedirectAllRequestsTo . |
HostName |
Host to which all requests to the bucket are redirected. Path: /WebsiteConfiguration/RedirectAllRequestsTo/HostName . |
Protocol |
Protocol used for redirects: http or https . This is an optional parameter.Path: /WebsiteConfiguration/RedirectAllRequestsTo/Protocol . |
Configuration example:
<!--Configuration for conditionally redirecting requests-->
<WebsiteConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<IndexDocument>
<Suffix>index.html</Suffix>
</IndexDocument>
<ErrorDocument>
<Key>Error.html</Key>
</ErrorDocument>
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>k8s/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>kubernetes/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
</WebsiteConfiguration>
Possible elements:
Element | Description |
---|---|
WebsiteConfiguration |
Top-level header of the website description. |
IndexDocument/Suffix |
Home page of the website. |
ErrorDocument/Key |
Document the user sees in case of 4xx errors. |
RoutingRules |
RoutingRule container.It must include at least one rule. |
RoutingRule |
Routing rule. It defines the conditions and conditional redirects. |
Condition |
Container of conditions to trigger the redirect. If a routing rule does not contain any conditions, all requests are redirected. The container must include at least one rule. |
KeyPrefixEquals |
This condition sets the name prefix for the object the requests are redirected from.KeyPrefixEquals is required if HttpErrorCodeReturnedEquals is not set. If KeyPrefixEquals and HttpErrorCodeReturnedEquals are set, the condition is met when both the parameters are true . |
HttpErrorCodeReturnedEquals |
This condition specifies the error code that triggers a redirect.HttpErrorCodeReturnedEquals is required if KeyPrefixEquals is not set. If KeyPrefixEquals and HttpErrorCodeReturnedEquals are set, the condition is met when both the parameters are true . |
Redirect |
Redirect container. You can redirect a request to a different page, different host, or change the protocol. RoutingRule must contain at least one Redirect element.A redirect must contain at least one of the following elements: Protocol , HostName , ReplaceKeyPrefixWith , ReplaceKeyWith , or HttpRedirectCode . |
Protocol |
In the Location header of the response, a redirect indicates which protocol, http or https , should be used.This parameter is optional if other redirects apply. |
HostName |
In the Location response header, the redirect indicates the host name to use.This parameter is optional if other redirects apply. |
ReplaceKeyPrefixWith |
The redirect specifies the object key name prefix to replace the KeyPrefixEquals value in the redirect request.It is incompatible with ReplaceKeyWith .This parameter is optional if other redirects apply. |
ReplaceKeyWith |
The redirect specifies the object key to use in the Location header.It is incompatible with ReplaceKeyPrefixWith .This parameter is optional if other redirects apply. |
HttpRedirectCode |
In the Location response header, the redirect specifies the HTTP redirect code .Possible values: any 3xx code.This parameter is optional if other redirects apply. |
Response
Headers
Responses can only contain common headers.
Response codes
For a list of possible responses, see Responses.