我在 Node.js 应用程序中运行 AWS SDK V3 Translate Client 来翻译句子。这是我的代码:
const { TranslateClient, CreateParallelDataCommand } = require("@aws-sdk/client-translate");
const client = new TranslateClient({
region: "ap-southeast-1",
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
}
});
const params = {
Text: "StackOverflow is very good.",
SourceLanguageCode: "en",
TargetLanguageCode: "id"
};
const command = new CreateParallelDataCommand(params);
function translate() {
return client.send(command)
.then((data) => {
console.log(data);
})
.catch((reason) => {
console.log(reason);
})
}
translate();
我已按照文档中的说明进行操作。
但是,结果如下。
TypeError: Cannot read property 'byteLength' of undefined
at Object.fromArrayBuffer (\projectDir\node_modules\@aws-sdk\util-buffer-from\dist-cjs\index.js:6:60)
at castSourceData (\projectDir\node_modules\@aws-sdk\hash-node\dist-cjs\index.js:29:31)
at Hash.update (\projectDir\node_modules\@aws-sdk\hash-node\dist-cjs\index.js:12:26)
at hmac (\projectDir\node_modules\@aws-sdk\signature-v4\dist-cjs\credentialDerivation.js:36:10)
at Object.getSigningKey (\projectDir\node_modules\@aws-sdk\signature-v4\dist-cjs\credentialDerivation.js:11:29)
at SignatureV4.getSigningKey (\projectDir\node_modules\@aws-sdk\signature-v4\dist-cjs\SignatureV4.js:139:39)
at SignatureV4.signRequest (\projectDir\node_modules\@aws-sdk\signature-v4\dist-cjs\SignatureV4.js:98:73)
at async \projectDir\node_modules\@aws-sdk\middleware-signing\dist-cjs\middleware.js:13:18
at async StandardRetryStrategy.retry (\projectDir\node_modules\@aws-sdk\middleware-retry\dist-cjs\StandardRetryStrategy.js:51:46)
at async \projectDir\node_modules\@aws-sdk\middleware-logger\dist-cjs\loggerMiddleware.js:6:22 {
'$metadata': { attempts: 1, totalRetryDelay: 0 }
}
这个问题的原因是什么,我该如何解决?