Tüm Ürünler
Search
Belge Merkezi

Object Storage Service:Delete files (Browser.js SDK)

Son Güncelleme:Oct 01, 2026

Artık ihtiyaç duymadığınız bir veya daha fazla dosyayı (Nesne) silebilirsiniz.

Uyarı

Silinen nesneler kurtarılamaz. Lütfen dikkatli olun.

Kullanım notları

  • Webpack ve Browserify gibi paketleme araçlarını kullanırken, npm install ali-oss komutunu çalıştırarak Browser.js için OSS SDK'yı yükleyin.

  • Bir tarayıcıdan OSS paketine erişmek istiyorsanız ancak paket için CORS kuralları yapılandırılmamışsa tarayıcı isteği reddeder. Bu nedenle, bir pakete tarayıcıdan erişmek istiyorsanız paket için CORS kurallarını yapılandırmanız gerekir. Daha fazla bilgi için bkz. Kurulum.

  • Browser.js için OSS SDK çoğunlukla tarayıcılarda kullanılır. AccessKey çiftinizin açığa çıkmasını önlemek için OSS'e erişirken Güvenlik Belirteci Hizmeti'nden (STS) alınan 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'tan meydana gelir. Geçici erişim kimlik bilgilerini nasıl alacağınız hakkında daha fazla bilgi için bkz. Geçici erişim yetkilendirmesi için STS kullanma.

Tek bir dosya silme

Aşağıdaki kod tek bir dosyayı siler:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <title>Document</title>
</head>

<body>
  <button id="delete">Delete</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 pair (AccessKey ID and AccessKey secret) obtained from STS.
      accessKeyId: 'yourAccessKeyId',
      accessKeySecret: 'yourAccessKeySecret',
      // The security token (SecurityToken) obtained from STS.
      stsToken: 'yourSecurityToken',
      // Specify the bucket name. For example, examplebucket.
      bucket: "examplebucket",
    });

    const deleteSingle = document.getElementById("delete");   

    // Delete a single file.
    deleteSingle.addEventListener("click", async () => {
      // Specify the name of the object to delete. The object name must be the full path of the object, not including the bucket name. For example, exampledir/exampleobject.txt.
      let result = await client.delete('exampledir/exampleobject.txt');
      console.log(result);
    });

  </script>
</body>

</html>

Birden fazla dosya silme

Aşağıdaki kod birden fazla dosyayı siler:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
  </head>

  <body>
    <button id="deleteAll">Delete multiple files</button>
    <!--Import the SDK file.-->
    <script
      type="text/javascript"
      src="https://gosspublic.alicdn.com/aliyun-oss-sdk-6.16.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 pair (AccessKey ID and AccessKey secret) obtained from STS.
        accessKeyId: 'yourAccessKeyId',
        accessKeySecret: 'yourAccessKeySecret',
        // The security token (SecurityToken) obtained from STS.
        stsToken: 'yourSecurityToken',
        // Specify the bucket name. For example, examplebucket.
        bucket: "examplebucket",
      });

      const deleteAll = document.getElementById("deleteAll");

      // Delete multiple files.
      deleteAll.addEventListener("click", async () => {
        // Specify the names of the objects to delete. The object names must be the full paths of the objects, not including the bucket name.
        let result = await client.deleteMulti([
          "example.txt",
          "exampleobject.txt",
          "newexampleobject.txt",
        ]);
        console.log(result);

        result = await client.deleteMulti(
          ["example.txt", "exampleobject.txt", "newexampleobject.txt"],
          {
            // Use the quiet parameter to specify whether to return a list of all deleted files. If quiet is set to true, OSS does not return a message body. If quiet is set to false, OSS returns a list of all deleted files.
            quiet: true,
          }
        );
      });
    </script>
  </body>
</html>

İlgili bilgiler