我正在使用 Nodejs - TS Express 服务器。我正在尝试从名为 tracker 的表中读取数据,该表的分区名称也为 tracker。我可以毫无问题地写入表,但是当我尝试使用 listEntities 或 getEntities 时,我得到
The requested operation is not implemented on the specified resource.
这是我用来获取列表的代码。我也尝试使用 sas 令牌,它也有同样的问题。
import { AzureNamedKeyCredential, TableClient, TableServiceClient, odata , AzureSASCredential, generateTableSas } from "@azure/data-tables";
import { Mail, MailEntity } from "../models/mail";
import { DefaultAzureCredential } from "@azure/identity";
const accountName = process.env.ACCOUNT_NAME || "";
const accountKey = process.env.ACCOUNT_KEY || "";
const tablesUrl = process.env.TABLES_URL || "";
const tableName = process.env.TABLE_NAME || "";
const sas_token = process.env.SAS_TOKEN || "";
const creds = new AzureNamedKeyCredential(accountName, accountKey)
const client = new TableClient(tablesUrl, tableName, creds);
client.listEntities({
queryOptions: { filter: odata`PartitionKey eq tracker` }
}).next().then((result)=>{
result.value.entities.forEach((res:MailEntity)=>{
console.log(res)
})
}).catch((error)=>{
console.log(error.message)
console.log("Error listing all entities")
})
我们在 Springboot 中尝试了一个示例项目,它使用相同的凭据运行得很好。我还读过其他一些人面临类似的问题,但他们要么没有提供解决方案,要么这些解决方案不起作用。
使用此参考我可以阅读Azure存储表中的详细信息。表 URL 将为
https://StorageaccountName.table.core.windows.net
。
代码:
import { TableClient } from "@azure/data-tables";
import * as dotenv from "dotenv";
dotenv.config();
const tablesUrl = process.env["TABLES_URL"] || "";
const sasToken = process.env["SAS_TOKEN"] || " ";
async function listAllEntities() {
console.log("== List All Entities Sample ==");
const tableName = `sampath123`;
const client = new TableClient(`${tablesUrl}${sasToken}`, tableName);
const listResults = client.listEntities();
for await (const entity of listResults) {
console.log(`PartitionKey: ${entity.partitionKey}, RowKey: ${entity.rowKey}`);
// Iterate through properties and log key-value pairs
for (const propName of Object.keys(entity)) {
if (propName !== 'partitionKey' && propName !== 'rowKey') {
console.log(`${propName}: ${entity[propName]}`);
}
}
}
}
export async function main() {
await listAllEntities();
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});
输出: