Elimine un solo objeto, varios objetos por nombre, los objetos que coincidan con un prefijo o un directorio completo.
Los objetos no se pueden restaurar después de eliminarlos. Tenga precaución al ejecutar esta operación.
Para evitar la interrupción del servicio o la pérdida de datos, no elimine ningún objeto dentro del directorio
.dlsdata/en un bucket donde OSS-HDFS esté habilitado.
Elimine un solo archivo
A continuación se muestra el código que elimina un objeto llamado exampleobject.txt de un bucket denominado examplebucket:
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')
Elimine archivos por lotes
El siguiente código elimina varios objetos por nombre:
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 #[]
Referencias
Para obtener más información sobre cómo eliminar un solo objeto, consulte la operación de API DeleteObject.
Para obtener más información sobre cómo eliminar varios objetos, consulte la operación de API DeleteMultipleObjects.