Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
Yandex Object Storage
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Buckets
      • Creating a bucket
      • Deleting a bucket
      • Limiting the maximum size of a bucket
      • Allowing public access to a bucket
      • Bucket encryption
      • Managing object lifecycles
      • Managing CORS configurations
      • Access policy management
      • Managing bucket versioning
      • Editing the ACL of a bucket
      • Enabling logging
      • Object lock management
    • Objects
      • Uploading an object
      • Getting information about an object
      • Downloading an object
      • Restoring an object's version
      • Getting a public link to an object
      • Configuring an object lock
      • Deleting an object
      • Deleting all objects
      • Deleting a partially uploaded object
      • Editing an object ACL
    • Static website hosting
      • Hosting setup
      • Support for your own domain
      • Support for multiple domain names
      • Configuring HTTPS
  • Tutorials
    • Getting object query statistics with S3 Select
    • Getting website traffic statistics with S3 Select
    • Generating a billing report with resource break-down using S3 Select
    • Server-side encryption
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Analyzing logs in DataLens
    • Using initialization scripts to configure GeeseFS in Yandex Data Proc
    • Mounting a bucket as a disk on Windows
    • Migrating data from Yandex Data Streams using Yandex Data Transfer
  • Concepts
    • Overview
    • Bucket
    • Objects
    • Bucket versioning
    • Object locks
    • Encryption
    • Object lifecycles
    • CORS
    • Static website hosting
    • Pre-signed URLs
    • Multipart upload
    • Access control lists (ACLs)
    • Bucket Policy
    • Uploading files via an HTML form
    • Storage class
    • Logging actions with a bucket
    • Backups
    • TLS protocol
    • S3 Select query language
    • Quotas and limits
  • Tools
    • All tools
    • Console clients
      • AWS CLI
      • S3cmd
    • File browsers
      • CyberDuck
      • WinSCP
    • SDK
      • AWS SDK for Java
      • Python SDK (boto)
      • AWS SDK for .NET
      • AWS SDK for C++
      • AWS SDK for PHP
      • AWS SDK for Go
    • FUSE
      • GeeseFS
      • s3fs
      • goofys
    • FTP
      • Docker container for (S)FTP(S)
  • API reference
    • REST (Amazon S3-compatible)
      • How to use the API
      • Signing requests
      • REST
        • All services and methods
        • Bucket
          • All methods
          • create
          • getBucketEncryption
          • getMeta
          • listObjects
          • listBuckets
          • deleteBucket
          • deleteBucketEncryption
          • putBucketEncryption
          • putBucketVersioning
          • getBucketVersioning
          • putBucketLogging
          • getBucketLogging
          • listObjectVersions
          • putObjectLockConfiguration
          • getObjectLockConfiguration
        • Object
          • All methods
          • upload
          • get
          • copy
          • getObjectMeta
          • delete
          • deleteMultipleObjects
          • options
          • selectObjectContent
          • putObjectRetention
          • putObjectLegalHold
          • getObjectRetention
          • getObjectLegalHold
        • Multipart upload
          • General multipart upload procedure
          • startUpload
          • uploadPart
          • copyPart
          • listParts
          • abortUpload
          • completeUpload
          • listUploads
        • Static Website Hosting
          • All methods
          • upload
          • get
          • delete
          • Static website response codes
        • CORS
          • All methods
          • XML structure of CORS configuration
          • upload
          • get
          • delete
        • Lifecycles
          • All methods
          • XML structure of lifecycle configuration
          • upload
          • get
          • delete
        • ACL
          • All methods
          • XML structure of ACL configuration
          • objectGetAcl
          • objectPutAcl
          • bucketGetAcl
          • bucketPutAcl
        • Bucket Policy
          • All methods
          • GetBucketPolicy
          • PutBucketPolicy
          • DeleteBucketPolicy
          • Data schema
          • Actions
          • Conditions
        • Common request headers
        • Common response headers
        • Responses
    • gRPC and REST
      • Authentication in the API
      • gRPC
        • Overview
        • BucketService
        • OperationService
      • REST
        • Overview
        • Bucket
          • Overview
          • create
          • delete
          • deleteHTTPSConfig
          • get
          • getHTTPSConfig
          • getStats
          • list
          • setHTTPSConfig
          • update
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before January 1, 2019
      • From January 1 to March 1, 2019
  • Questions and answers
  1. Step-by-step instructions
  2. Objects
  3. Uploading an object

Uploading an object

Written by
Yandex Cloud
  • Regular uploads
  • Uploading an object version with an object lock

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

Management console
AWS CLI
Terraform

In the management console, you can work with Object Storage buckets like a hierarchical file system.

To upload an object:

  1. In the management console, select the folder to upload an object to.
  2. Select Object Storage.
  3. Click the name of the desired bucket.
  4. 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.
  5. Once you are in the appropriate folder, click Upload.
  6. In the window that opens, select the required files and click Open.
  7. 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.
  8. Click Upload.
  9. Refresh the page.
  1. If you don't have the AWS CLI yet, install and configure it.

  2. 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:

  1. 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.

  2. Make sure that the configuration files are valid.

    1. In the command line, go to the directory where you created the configuration file.

    2. 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.

  3. Deploy the cloud resources.

    1. If the configuration doesn't contain any errors, run the command:

      terraform apply
      
    2. 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.

AWS CLI
  1. If you don't have the AWS CLI yet, install and configure it.

  2. 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 the object-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 and object-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:

AWS CLI
  1. Calculate a file's MD5 hash and encode it with Base64:

    md5=($(md5sum <path_to_local_file>))
    md5_base64=$(echo $md5 | base64)
    
  2. If you don't have the AWS CLI yet, install and configure it.

  3. 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 and object-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.

Was the article helpful?

Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
In this article:
  • Regular uploads
  • Uploading an object version with an object lock