OSS, nesnelerin doğrudan yeniden adlandırılmasını desteklemez. Bir nesneyi yeniden adlandırmak için kopyala ve sil işlemini uygulayın: İstenen ada sahip yeni bir nesne oluşturmak için CopyObject yöntemini çağırın, ardından kaynak nesneyi kaldırmak için DeleteObject yöntemini çağırın.
Kullanım notları
Bu konudaki örnek kodu çalıştırmadan önce, özel alan adı veya Security Token Service (STS) gibi yöntemleri kullanarak bir OSSClient örneği oluşturmanız gerekir. Daha fazla bilgi için bkz. Başlatma (Android SDK).
Örnek kod
Aşağıdaki kod, examplebucket paketindeki srcobject.txt nesnesini destobject.txt olarak yeniden adlandırır:
// Specify the name of the bucket.
String bucketName = "examplebucket";
// Specify the full path of the source object. Do not include the bucket name in the full path. Example: srcobject.txt.
String sourceObjectKey = "srcobject.txt";
// Specify the full path of the destination object. Do not include the bucket name in the full path. Example: destobject.txt.
String objectKey = "destobject.txt";
try {
CopyObjectRequest copyObjectRequest = new CopyObjectRequest(bucketName, sourceObjectKey, bucketName, objectKey);
oss.copyObject(copyObjectRequest);
// Delete the srcobject.txt object.
DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucketName, sourceObjectKey);
oss.deleteObject(deleteObjectRequest);
} catch (ClientException e) {
// Handle client-side exceptions, such as network errors.
e.printStackTrace();
} catch (ServiceException e) {
// Handle server-side exceptions.
Log.e("RequestId", e.getRequestId());
Log.e("ErrorCode", e.getErrorCode());
Log.e("HostId", e.getHostId());
Log.e("RawMessage", e.getRawMessage());
}
Dizinler de doğrudan yeniden adlandırılamaz. Her nesne ve alt dizin için aynı kopyala ve sil yaklaşımını uygulayın.
İlgili bilgiler
Bir nesneyi yeniden adlandırmaya yönelik API işlemleri hakkında daha fazla bilgi için bkz. CopyObject ve DeleteObject.
Bir OSSClient örneğini nasıl başlatacağınızı öğrenmek için bkz. Android için bir OSSClient örneği başlatma.