loading...
上次更新: 2024-05-06
這篇文章是使用 node.js
node.js 專案並配置授權node.js 專案npm initnpm install --save @google-cloud/storagejson 檔嗎?
我們要在終端機輸入以下代碼,"[PATH]" 要替換為剛剛存放 json金鑰的位置export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"// Imports the Google Cloud client library
const { Storage } = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
// 帶入自己的 bucket 名稱
const bucketName = 'your_bucket_name';
async function listFiles() {
// Lists files in the bucket
const [files] = await storage.bucket(bucketName).getFiles();
console.log('Files:');
files.forEach(file => {
console.log(file.name);
});
}
listFiles().catch(console.error);