Bu konuda, tek bir nesnenin veya birden fazla nesnenin aynı anda nasıl silineceği açıklanmaktadır.
Silinen nesneler geri yüklenemez. Nesneleri silerken dikkatli olun.
Kullanım notları
Bir nesneyi silmek için nesnenin depolandığı paket üzerinde yazma iznine sahip olmanız gerekir.
Bu konudaki örnek kodu çalıştırmadan önce özel alan adı veya Security Token Service (STS) gibi yöntemler kullanarak bir OSSClient örneği oluşturmalısınız. Daha fazla bilgi için bkz. Başlatma (Android SDK).
Tek bir nesne silme
Aşağıdaki örnek kod, examplebucket adlı bir paketten exampleobject.txt adlı bir nesnenin nasıl silineceğini gösterir:
// Create a delete request.
// Specify the bucket name (for example, examplebucket) and the full path of the object (for example, exampledir/exampleobject.txt). The full path of the object cannot contain the bucket name.
DeleteObjectRequest delete = new DeleteObjectRequest("examplebucket", "exampledir/exampleobject.txt");
// Delete the object asynchronously.
OSSAsyncTask deleteTask = oss.asyncDeleteObject(delete, new OSSCompletedCallback<DeleteObjectRequest, DeleteObjectResult>() {
@Override
public void onSuccess(DeleteObjectRequest request, DeleteObjectResult result) {
Log.d("asyncDeleteObject", "success!");
}
@Override
public void onFailure(DeleteObjectRequest request, ClientException clientExcepion, ServiceException serviceException) {
// Request error.
if (clientExcepion != null) {
// A client exception occurred, such as a network exception.
clientExcepion.printStackTrace();
}
if (serviceException != null) {
// A server exception occurred.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
Aynı anda birden fazla nesne silme
Aynı anda en fazla 1.000 nesne silebilirsiniz.
Silme sonucu aşağıdaki iki moddan birinde döndürülür. İhtiyaçlarınıza göre bir dönüş modu seçin.
verbose (varsayılan): isQuiet belirtilmezse veya false olarak ayarlanırsa silinen tüm nesnelerin listesi döndürülür.
quiet: isQuiet true olarak ayarlanırsa silinemeyen nesnelerin listesi döndürülür.
Aşağıdaki örnek kod, examplebucket adlı bir paketten belirtilen birden fazla nesnenin nasıl silineceğini ve sonucun quiet modunda nasıl döndürüleceğini gösterir:
// Specify the full paths of the objects that you want to delete. The full paths of the objects cannot contain the bucket name.
List<String> objectKeys = new ArrayList<String>();
objectKeys.add("exampleobject.txt");
objectKeys.add("testfolder/sampleobject.txt");
// Set the mode to basic mode to return only the list of files that failed to be deleted.
DeleteMultipleObjectRequest request = new DeleteMultipleObjectRequest("examplebucket", objectKeys, true);
oss.asyncDeleteMultipleObject(request, new OSSCompletedCallback<DeleteMultipleObjectRequest, DeleteMultipleObjectResult>() {
@Override
public void onSuccess(DeleteMultipleObjectRequest request, DeleteMultipleObjectResult result) {
Log.i("DeleteMultipleObject", "success");
}
@Override
public void onFailure(DeleteMultipleObjectRequest request, ClientException clientException, ServiceException serviceException) {
// Request error.
if (clientException != null) {
// A client exception occurred, such as a network exception.
clientException.printStackTrace();
}
if (serviceException != null) {
// A server exception occurred.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
Başvurular
-
Tek bir nesne silme
Tek bir nesne silmek için çağırabileceğiniz API işlemi hakkında daha fazla bilgi için bkz. DeleteObject.
-
Aynı anda birden fazla nesne silme
Aynı anda birden fazla nesne silmek için çağırabileceğiniz API işlemi hakkında bilgi için bkz. DeleteMultipleObjects.
Bir OSSClient örneğinin nasıl başlatılacağı hakkında daha fazla bilgi için bkz. Başlatma.