Uploading an object
You can create folders inside buckets and upload objects there. Keep in mind that in the SDK and HTTP API, an object key is the entire path to the object from the bucket root. For more information, see Objects.
Note
You cannot upload objects greater than 5 GB in size via the management console (see Quotas and limits in Object Storage). Also, when uploading via the console, you can't set content-type
or other headers. To upload large objects or specify object headers, use other tools.
Regular uploads
In the management console, you can work with Object Storage buckets like a hierarchical file system.
To upload an object:
- In the management console, select the folder to upload an object to.
- Select Object Storage.
- Click the name of the desired bucket.
- If you want to upload the object to a particular folder, go to that folder by clicking on its name. If you want to create a new folder, click Create folder.
- Once you are in the appropriate folder, click Upload.
- In the window that opens, select the required files and click Open.
- The management console displays all the objects selected for uploading and prompts you to select a storage class. The default storage class is defined in the bucket settings.
- Click Upload.
- Refresh the page.
-
If you don't have the AWS CLI yet, install and configure it.
-
To upload a single object, run the command:
aws --endpoint-url=https://storage.yandexcloud.net/ \ s3 cp <path_to_local_file>/ s3://<bucket_name>/<object_key>
Where:
<path_to_local_file>
: Path to the file to be uploaded to the bucket.<bucket_name>
: Your bucket's name.<object_key>
: Key to store the object in the bucket with.
To load all objects from the local directory, use the following command:
aws --endpoint-url=https://storage.yandexcloud.net/ \ s3 cp --recursive <path_to_local_directory>/ s3://<bucket_name>/<prefix>/
Where:
<path_to_local_directory>
: Path to the folder from which you need to copy files to the bucket.<bucket_name>
: Your bucket's name.<prefix>
: ID of a folder in storage, described in Directory.
The aws s3 cp
command is high-level, its functionality is limited. For more information, see the AWS CLI reference. All the upload functionality that Object Storage supports can be used when running the aws s3api put-object command (see sample operations with object locks below).
With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it by configuration files. They store the infrastructure description in HashiCorp Configuration Language (HCL). Terraform and its providers are distributed under the Mozilla Public License.
For more information about the provider resources, see the documentation on the Terraform site or mirror site.
If you change the configuration files, Terraform automatically determines which part of your configuration is already deployed and what should be added or removed.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
Before you start, retrieve the static access keys: a secret key and a key ID used for authentication in Object Storage.
To create an object in an existing bucket:
-
In the configuration file, describe the parameters of resources that you want to create:
resource "yandex_storage_object" "test-object" { access_key = "<static_key_ID>" secret_key = "<secret_key>" bucket = "<bucket_name>" key = "<object_name>" source = "<file_path>" }
Where:
-
access_key
: The ID of the static access key. -
secret_key
: The value of the secret access key. -
bucket
: Name of the bucket to add the object to. Required parameter. -
key
: Name of the object in the bucket. Required parameter. Name format:- The length can be from 3 to 63 characters.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter. The last character can't be a hyphen.
-
source
: Relative or absolute path to the files you need to upload to the bucket.
For more information about resources you can create with Terraform, see the provider documentation.
-
-
Make sure that the configuration files are valid.
-
In the command line, go to the directory where you created the configuration file.
-
Run the check using the command:
terraform plan
If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If the configuration contains errors, Terraform will point them out.
-
-
Deploy the cloud resources.
-
If the configuration doesn't contain any errors, run the command:
terraform apply
-
Confirm the resource creation: type
yes
in the terminal and press Enter.Afterwards, all the necessary resources are created in the specified folder. You can check that the resources are there with the correct settings using the management console.
-
Uploading an object version with an object lock
If a bucket has versioning and object lock enabled, you can specify object lock settings (disable deleting or overwriting) when uploading an object version.
-
If you don't have the AWS CLI yet, install and configure it.
-
Run the command:
aws --endpoint-url=https://storage.yandexcloud.net/ \ s3api put-object \ --body <path_to_local_file> \ --bucket <bucket_name> \ --key <object_key> \ --object-lock-mode <type_of_object_lock_with_retention_period> \ --object-lock-retain-until-date <object_lock_retain_until_date_and_time> \ --object-lock-legal-hold-status <status_of_legal_hold>
Where:
-
body
: Path to the file to be uploaded to the bucket. -
bucket
: Your bucket's name. -
key
: Key to store the object in the bucket with. -
object-lock-mode
: Type of object lock set for a certain period:GOVERNANCE
: An object lock with a predefined retention period that can be managed.COMPLIANCE
: An object lock with a predefined retention period with strict compliance.
-
object-lock-retain-until-date
Date and time until which an object is to be locked, specified in any format described in the HTTP standard. For example,Mon, 12 Dec 2022 09:00:00 GMT
. Can only be set together with theobject-lock-mode
parameter. -
object-lock-legal-hold-status
: Legal hold status:ON
: Enabled.OFF
: Disabled.
You can place an object version only under an object lock with a retention period (the
object-lock-mode
andobject-lock-retain-until-date
parameters), only under a legal hold (object-lock-legal-hold-status
), or under both. For more information about their combined use, see Object lock types. -
If a bucket already has the default object locks set for a certain period configured, you should upload any objects to it with their MD5 hash specified:
-
Calculate a file's MD5 hash and encode it with Base64:
md5=($(md5sum <path_to_local_file>)) md5_base64=$(echo $md5 | base64)
-
If you don't have the AWS CLI yet, install and configure it.
-
Upload an object to the bucket:
aws --endpoint-url=https://storage.yandexcloud.net/ \ s3api put-object \ --body <path_to_local_file> \ --bucket <bucket_name> \ --key <object_key> \ --content-md5 $md5_base64
Where:
body
: Path to the file to be uploaded to the bucket.bucket
: Your bucket's name.key
: Key to store the object in the bucket with.content-md5
: Object's encoded MD5 hash.
You can also add the following parameters to the command:
object-lock-mode
andobject-lock-retain-until-date
to place an object version under an object lock for a certain period with a configuration different from the bucket's object lock default settings.object-lock-legal-hold-status
to place an object version under a legal hold.
For more information about these parameters, see the instructions above.