Todos os produtos
Search
Central de documentação

Object Storage Service:Manage object metadata (Ruby SDK)

Última atualização: Jul 03, 2026

Os objetos armazenados no Object Storage Service (OSS) contêm uma chave, dados e metadados. Os metadados descrevem as propriedades do objeto e incluem cabeçalhos HTTP padrão e metadados definidos pelo usuário. Defina cabeçalhos HTTP padrão para personalizar políticas de requisição HTTP, como a política de cache ou de download forçado do objeto. Configure também metadados personalizados para identificar a finalidade ou outras características do objeto.

Importante

  • No kit de desenvolvimento de software (SDK) para Ruby, um Hash representa os metadados do objeto. As chaves e os valores devem ser do tipo String.

  • Os metadados integram os cabeçalhos HTTP. O protocolo HTTP determina que os cabeçalhos de requisição não podem conter caracteres complexos. Utilize apenas caracteres ASCII simples e visíveis, sem quebras de linha.

  • O tamanho total dos metadados não pode exceder 8 KB.

Definir metadados de objetos

Use o código a seguir para definir os metadados durante o upload de um objeto.

require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  # Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)

# Specify the bucket name. Example: examplebucket.
bucket = client.get_bucket('examplebucket')

# Set object metadata during a simple upload.
bucket.put_object(
  'my-object-1',
  :file => 'local-file',
  :metas => {'year' => '2016', 'people' => 'mary'})

# Set object metadata during an append upload.
bucket.append_object(
  'my-object-2', 0,
  :file => 'local-file',
  :metas => {'year' => '2016', 'people' => 'mary'})

# Set object metadata during a resumable upload.
bucket.resumable_upload(
  'my-object',
  'local-file',
  :metas => {'year' => '2016', 'people' => 'mary'})          

Modificar metadados de objetos

Execute o código a seguir para modificar os metadados de um objeto existente.

require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  # Specify the endpoint of the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
   # Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)

# Specify the bucket name. Example: examplebucket.
bucket = client.get_bucket('examplebucket')
# Modify the object metadata.
bucket.update_object_metas('my-object', {'year' => '2017'})            

Referências

  • Para obter mais informações sobre como definir metadados em uploads simples, consulte a operação da API PutObject.

  • Para modificar metadados ao copiar um objeto, consulte a operação da API CopyObject.