ページ分けされたファイルリストを表示する

バケット内のオブジェクトのリストを自動ページングなしで表示し、次のオブジェクト セットに移動できるようにします。

コードサンプル

Node.js

詳細については、Cloud Storage Node.js API のリファレンス ドキュメントをご覧ください。

Cloud Storage に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証を設定するをご覧ください。

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// The ID of your GCS bucket
// const bucketName = 'your-unique-bucket-name';

// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

async function listFilesPaginated() {
  const bucket = storage.bucket(bucketName);
  const [files, queryForPage2] = await bucket.getFiles({autoPaginate: false});

  console.log('Files:');
  files.forEach(file => {
    console.log(file.name);
  });

  // Page through the next set of results using "queryForPage2"
  if (queryForPage2 !== null) {
    const [files, queryForPage3] = await bucket.getFiles(queryForPage2);

    console.log('Files:');
    files.forEach(file => {
      console.log(file.name);
    });

    // If necessary, continue cursoring using "queryForPage3"
  }
}

listFilesPaginated().catch(console.error);

次のステップ

他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。