【发布时间】:2021-10-14 19:20:01
【问题描述】:
在我的 Protractor 测试套件执行完成后,我正在尝试将我的 html 结果文件上传到 AWS S3。我在自动化中使用 JavaScript。请帮我解决这里的错误:
static uploadtoS3() {
const AWS = require('aws-sdk');
var FILE_NAME_LOCAL;
var crypt = require("crypto");
fs.readdirSync("./reports/html/").forEach(file => {
if (file.startsWith("execution_report")) {
FILE_NAME_LOCAL = process.cwd() + "\\reports\\html\\" + file;
}
});
console.log("File name: " + FILE_NAME_LOCAL);
// Get file stream
const fileStream = fs.createReadStream(FILE_NAME_LOCAL);
var hash = crypt.createHash("md5")
.update(new Buffer.from(FILE_NAME_LOCAL, 'binary'))
.digest("base64");
console.log("Hash: "+hash);
// Call S3 to retrieve upload file to specified bucket
const uploadParams = {
Bucket: 'my.bucket',
Key: 'automation_report.html',
Body: fileStream,
ContentType: "text/html",
ContentMD5: hash,
// CacheControl: "max-age=0,no-cache,no-store,must-revalidate",
ACL: 'public-read',
};
const s3 = new AWS.S3({
// TODO: use this `accessKeyId: <key>` annotation to indicate the presence of a key instead of placing the actual key here.
endpoint: "https://3site-abc-wip1.nam.nsroot.net",
accessKeyId: <access_key_id>,
secretAccessKey: <secret_access_key>,
signatureVersion: 'v4',
ca: fs.readFileSync('C:\\Users\\AB11111\\InternalCAChain_PROD.pem'),
sslEnabled: true
});
// Create S3 service object and upload
s3.upload(uploadParams, function (err, data) {
console.log("Inside upload..");
if (err) {
throw err;
} if (data) {
console.log('Upload Success. File location:' + data.Location);
}
});
}
错误:无法在以下位置获取本地颁发者证书 TLSSocket.emit 上的 TLSSocket.onConnectSecure (_tls_wrap.js:1049:34) (events.js:182:13) 在 TLSSocket.EventEmitter.emit (domain.js:442:20) 在 TLSSocket._finishInit (_tls_wrap.js:631:8)
【问题讨论】:
-
您是否设置了正确的凭据?你错过了
AWS.config.update({ accessKeyId, secretAccessKey }); -
谢谢,但
AWS.config.update({ accessKeyId, secretAccessKey });没有帮助。我确定凭据。 -
我只是希望它们不是有效的凭据
-
您不认为错误的凭据会产生错误吗?我没有看到任何错误。
-
我已经用我最近遇到的错误更新了我的问题。我请求你再调查一下。
标签: javascript amazon-web-services amazon-s3 protractor