VK Cloud logo

CORS error when uploading files to a bucket by a web application

A web application attempts to upload a file to a VK Object Storage bucket, but the request is blocked by the browser. The developer console displays an error related to CORS rules, for example, Access to XMLHttpRequest at '...' from origin '...' has been blocked by CORS policy.

The problem occurs due to the web browser security mechanism Same-Origin Policy (SOP). This mechanism prevents a script on one origin from making requests to another origin unless it is explicitly allowed. To allow such interaction, VK Object Storage must return special HTTP headers.

Solution

Check and fix the CORS rules:

  1. Go to the VK Cloud management console.

  2. Select the project that contains the target bucket.

  3. Go to the Object Storage → Buckets section.

  4. Click Menu for the target bucket and select Settings.

  5. Go to the CORS tab.

  6. Add or edit the CORS rule:

    • AllowedOrigins: specify the domain of your web application. Using the * character will allow access from any domain.
    • AllowedMethods: specify the HTTP method that your web application uses for uploading, for example, PUT or POST.
    • AllowedHeaders: specify the allowed request headers from the web application, for example, Content-Type, Authorization, x-amz-acl. Using the * character will allow requests with any headers.
Was this article helpful?