Android için Object Storage Service (OSS) SDK, bir pakette belirli bir nesnenin var olup olmadığını kontrol etmek için kullanışlı bir senkron API sunar.
Kullanım notları
Bir nesnenin var olup olmadığını belirlemek için
oss:GetObjectiznine sahip olmanız gerekir. Daha fazla bilgi için bkz. RAM kullanıcısına özel ilke ekleme.Bu konudaki örnek kodu çalıştırmadan önce, özel etki alanı adı veya Security Token Service (STS) gibi yöntemleri kullanarak bir OSSClient örneği oluşturmalısınız. Daha fazla bilgi için bkz. Başlatma (Android SDK).
Örnekler
Aşağıdaki örnek kod, examplebucket adlı bir pakette exampleobject.txt adlı bir nesnenin var olup olmadığını nasıl belirleyeceğinizi gösterir:
try {
// Specify the name of the bucket and the full path of the object. In this example, the bucket name is examplebucket and the full path of the object is exampledir/exampleobject.txt. Do not include the bucket name in the full path.
if (oss.doesObjectExist("examplebucket", "exampledir/exampleobject.txt")) {
Log.d("doesObjectExist", "object exist.");
} else {
Log.d("doesObjectExist", "object does not exist.");
}
} catch (ClientException e) {
// Handle client exceptions, such as network exceptions.
e.printStackTrace();
} catch (ServiceException e) {
// Handle service exceptions.
Log.e("ErrorCode", e.getErrorCode());
Log.e("RequestId", e.getRequestId());
Log.e("HostId", e.getHostId());
Log.e("RawMessage", e.getRawMessage());
}
İlgili bilgiler
Bir OSSClient örneğini başlatma hakkında daha fazla bilgi için bkz. Başlatma (Android SDK).
Kullanıcı izinlerini yönetmek üzere bir RAM ilkesi yapılandırma hakkında daha fazla bilgi için bkz. RAM kullanıcısına özel ilke ekleme.