Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Delete files (Ruby SDK)

Son Güncelleme:Oct 01, 2026

Tek bir nesneyi, ada göre birden çok nesneyi, önekle eşleşen nesneleri veya tüm bir dizini silin.

Uyarı
  • Nesneler silindikten sonra geri yüklenemez. Bu işlemi gerçekleştirirken dikkatli olun.

  • Hizmet kesintisini veya veri kaybını önlemek için OSS-HDFS etkinleştirilmiş bir paketteki .dlsdata/ dizini içindeki hiçbir nesneyi silmeyin.

Tek bir dosyayı silme

Aşağıdaki kod, examplebucket adlı bir paketten exampleobject.txt adlı bir nesneyi siler:

require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  # Set Endpoint to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set 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 code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Set the bucket name. For example, examplebucket.
bucket = client.get_bucket('examplebucket')
# Set the full path of the object. For example, exampledir/exampleobject.txt. The full path cannot contain the bucket name.
bucket.delete_object('exampledir/exampleobject.txt')            

Birden çok dosyayı toplu olarak silme

Aşağıdaki kod, ada göre birden çok nesneyi siler:

require 'aliyun/oss'
client = Aliyun::OSS::Client.new(
  # Set Endpoint to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set 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 code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Set the bucket name. For example, examplebucket.
bucket = client.get_bucket('examplebucket')
# Set the full paths of the objects to delete. The full paths cannot contain the bucket name.
objs = ['my-object-1', 'my-object-2']
result = bucket.batch_delete_objects(objs)
# By default, the successfully deleted objects are returned.
puts result #['my-object-1', 'my-object-2']

objs = ['my-object-3', 'my-object-4']
result = bucket.batch_delete_objects(objs, :quiet => true)
# The deletion result is not returned.
puts result #[]            

İlgili konular

  • Tek bir nesnenin silinmesi hakkında daha fazla bilgi için bkz. DeleteObject API işlemi.

  • Birden çok nesnenin silinmesi hakkında daha fazla bilgi için bkz. DeleteMultipleObjects API işlemi.