Arşiv ve Soğuk Arşiv nesnelerinin okunabilmesi için öncelikle geri yüklenmesi gerekir. Bu konuda, Arşiv ve Soğuk Arşiv nesnelerinin nasıl geri yükleneceği açıklanmaktadır.
Kullanım notları
Webpack ve Browserify gibi paketleme araçlarını kullanırken, OSS SDK for Browser.js'i npm install ali-oss komutunu çalıştırarak yükleyin.
Bir tarayıcıdan OSS paket erişmek istediğinizde ancak paket için CORS kuralları yapılandırılmamışsa tarayıcı isteği reddeder. Bu nedenle, bir pakete tarayıcı üzerinden erişmek istiyorsanız paket için CORS kurallarını yapılandırmanız gerekir. Daha fazla bilgi için bkz. Kurulum.
-
OSS SDK for Browser.js çoğunlukla tarayıcılarda kullanılır. AccessKey çiftinizin açığa çıkmasını önlemek için OSS'e erişirken Security Token Service (STS) üzerinden elde edilen geçici erişim kimlik bilgilerini kullanmanızı öneririz.
Geçici erişim kimlik bilgileri; bir AccessKey çifti ve bir güvenlik belirtecinden oluşur. AccessKey çifti, bir AccessKey ID ve bir AccessKey Secret içerir. Geçici erişim kimlik bilgilerini nasıl elde edeceğiniz hakkında daha fazla bilgi için bkz. Geçici erişim yetkilendirmesi için STS kullanma.
Arşiv nesnesini geri yükleme
Aşağıdaki kod, bir Arşiv nesnesinin nasıl geri yükleneceğini göstermektedir:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<button id='upload'>Upload</button>
<button id='restore'>Restore File</button>
<!--Import the SDK file.-->
<script type="text/javascript" src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.0.min.js"></script>
<script type="text/javascript">
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
region: 'yourRegion',
authorizationV4: true,
// The temporary AccessKey ID and AccessKey secret obtained from STS.
accessKeyId: 'yourAccessKeyId',
accessKeySecret: 'yourAccessKeySecret',
// The security token (SecurityToken) obtained from STS.
stsToken: 'yourSecurityToken',
// The bucket name. For example, examplebucket.
bucket: "examplebucket",
});
const upload = document.getElementById('upload')
const restore = document.getElementById('restore')
// Specify the content of the file to upload.
const file = new Blob(['examplecontent'])
// Specify the name of the object to be stored in the bucket.
const fileName = 'example.txt'
// Upload the file and set its storage class to Archive.
upload.addEventListener('click', () => {
client.put(fileName, file, {
headers: {
'x-oss-storage-class': 'Archive'
}
}).then(r => console.log(r))
})
// Restore the Archive object.
restore.addEventListener('click', () => {
client.restore(fileName).then(r => console.log(r))
})
</script>
</body>
</html>
Soğuk Arşiv nesnesini geri yükleme
Aşağıdaki kod, bir Soğuk Arşiv nesnesinin nasıl geri yükleneceğini göstermektedir:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Document</title>
</head>
<body>
<button id='upload'>Upload</button>
<button id='restore'>Restore File</button>
<!--Import the SDK file.-->
<script type="text/javascript" src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.18.0.min.js"></script>
<script type="text/javascript">
const client = new OSS({
// Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
region: 'yourRegion',
authorizationV4: true,
// The temporary AccessKey ID and AccessKey secret obtained from STS.
accessKeyId: 'yourAccessKeyId',
accessKeySecret: 'yourAccessKeySecret',
// The security token (SecurityToken) obtained from STS.
stsToken: 'yourSecurityToken',
// The bucket name. For example, examplebucket.
bucket: "examplebucket",
});
const upload = document.getElementById("upload");
const restore = document.getElementById("restore");
// Specify the content of the file to upload.
const file = new Blob(["examplecontent"]);
// Specify the name of the object to be stored in the bucket.
const fileName = "example1.txt";
// Upload the file and set its storage class to ColdArchive.
upload.addEventListener("click", () => {
client
.put(fileName, file, {
headers: {
"x-oss-storage-class": "ColdArchive",
},
})
.then((r) => console.log(r));
});
// Expedited: The object is restored within 1 hour.
// Standard: The object is restored within 2 to 5 hours. If you do not specify the JobParameters parameter, Standard is used by default.
// Bulk: The object is restored within 5 to 12 hours.
// Days specifies the number of days that the object remains in the restored state. The valid range is 1 to 7.
// Restore the Cold Archive object.
restore.addEventListener("click", () => {
client
.restore(fileName, {
type: "ColdArchive",
// Specifies the restoration priority.
// Expedited: The object is restored within 1 hour.
// Standard: The object is restored within 2 to 5 hours.
// Bulk: The object is restored within 5 to 12 hours.
JobParameters: "Bulk",
// The number of days that the object remains in the restored state. The default value is 1.
Days: 2,
})
.then((r) => console.log(r));
});
</script>
</body>
</html>
İlgili kaynaklar
Arşiv ve Soğuk Arşiv nesnelerinin nasıl geri yükleneceğini gösteren tam kod örnekleri için bkz. GitHub Örnekleri.
Arşiv ve Soğuk Arşiv nesnelerini geri yüklemeye yönelik API işlemi hakkında daha fazla bilgi için bkz. RestoreObject.