CORS
The VK Object Storage service allows you to manage the CORS configuration of a bucket. To upload a CORS configuration, you need to create an XML document.
List of available methods for bucket CORS configurations:
- GetBucketCORS — Get the list of CORS configurations for a bucket.
- PutBucketCORS — Set a CORS configuration.
- DeleteBucketCORS — Delete a CORS configuration.
<CORSConfiguration><CORSRule><AllowedOrigin>URL</AllowedOrigin><AllowedMethod>HTTP_Method</AllowedMethod><AllowedHeader>Header_Name</AllowedHeader>...</CORSRule>...</CORSConfiguration>
The GET operation returns information about the CORS configuration set for the bucket.
To use this operation, you must have WRITE_ACP write permissions. The bucket owner has this permission by default and can grant it to other users.
Request example:
GET /?cors HTTP/1.1Host: my-test-bucket1.hb.ru-msk.vkcloud-storage.rux-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855x-amz-date: 20200831T185319ZAuthorization: AWS4-HMAC-SHA256 Credential=II5JDQBAN3JYM4DNEB6C/20200831/ru-msk/s3/aws4_request,SignedHeaders=host;x-amz-content-sha256;x-amz-date,Signature=f7d7879992a9f3a06ddacd59e53ac318e99b2ed6230692b30099739e34469a91
Response example:
HTTP/1.1 200 OKDate: Mon, 31 Aug 2020 18:53:20 GMTx-amz-request-id: tx00000000000000279651f-005963cd20-1268c-ru-mskaContent-Type: application/xmlContent-Length: 430Connection: close<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><CORSRule><AllowedMethod>PUT</AllowedMethod><AllowedMethod>DELETE</AllowedMethod><AllowedMethod>POST</AllowedMethod><AllowedOrigin>http://example.com</AllowedOrigin><AllowedHeader>\*</AllowedHeader></CORSRule><CORSRule><AllowedMethod>GET</AllowedMethod><AllowedOrigin>\*</AllowedOrigin></CORSRule></CORSConfiguration>
The PUT operation sets the CORS configuration for the bucket. If a configuration already exists, it is overwritten.
To use this operation, you must have WRITE_ACP write permissions.
You can set this configuration on a bucket so that it can serve cross-origin requests. For example, you can grant a request from the http://www.example.com origin access to the my.example.bucket.com bucket using the browser's XMLHttpRequest functionality.
To enable cross-origin resource sharing (CORS) on a bucket, you need to add a CORS subresource to the bucket. The CORS subresource is an XML document that configures the rules defining the origins and HTTP methods that can be used with your bucket. The maximum document size is 64 KB. For example, the CORS configuration on a bucket might have the following two rules set:
- The first CORSRule rule allows
PUT,POST, andDELETEcross-origin requests from thehttps://www.example.comorigin. This rule also allows using all headers in a preflightOPTIONSrequest via theAccess-Control-Request-Headersheader. Consequently, in response to any preflightOPTIONSrequest, the service returns any requested header. - The second rule allows
GETcross-origin requests from all origins. The*wildcard indicates that any origin can be used.
Request example:
PUT /?cors HTTP/1.1Host: my-test-bucket1.hb.ru-msk.vkcloud-storage.ruContent-Length: 374Content-Type: application/xmlx-amz-content-sha256: 745320970930725bd18820ec990f7334960f0a47358be189e77504cc094be77ex-amz-date: 20200831T185043ZAuthorization: AWS4-HMAC-SHA256 Credential=II5JDQBAN3JYM4DNEB6C/20200831/ru-msk/s3/aws4_request,SignedHeaders=content-md5;content-type;host;x-amz-content-sha256;x-amz-date,Signature=f52b2bfb6ec975c86cadd2e51a6ee9842c6151b737e46ce90a3cb3cc0d0dea97<CORSConfiguration><CORSRule><AllowedOrigin>http://example.com</AllowedOrigin><AllowedMethod>PUT</AllowedMethod><AllowedMethod>POST</AllowedMethod><AllowedMethod>DELETE</AllowedMethod><AllowedHeader>\*</AllowedHeader></CORSRule><CORSRule><AllowedOrigin>\*</AllowedOrigin><AllowedMethod>GET</AllowedMethod></CORSRule></CORSConfiguration>
Response example:
HTTP/1.1 200 OKDate: Mon, 31 Aug 2020 18:50:44 GMTx-amz-request-id: tx0000000000000027946fc-005963cc84-1268c-ru-mskaContent-Type: application/xmlContent-Length: 0Connection: close
The DELETE operation deletes information about the CORS configuration set for the bucket.
To use this operation, you must have WRITE_ACP write permissions.
Request example:
DELETE /?cors HTTP/1.1Host: my-test-bucket1.hb.ru-msk.vkcloud-storage.rux-amz-content-sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855x-amz-date: 20200831T182537ZAuthorization: AWS4-HMAC-SHA256 Credential=II5JDQBAN3JYM4DNEB6C/20200831/ru-msk/s3/aws4_request,SignedHeaders=content-md5;content-type;host;x-amz-content-sha256;x-amz-date,Signature=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
Response example:
HTTP/1.1 204 No ContentDate: Mon, 31 Aug 2020 18:25:38 GMTx-amz-request-id: tx0000000000000002fae1f-0059690ca2-6441-ru-mskaConnection: close