mongodb - StitchServiceError "aws: "aws_service" 是必需的字符串", errorCodeName: InvalidParameter
问题描述
我正在设置 AWS S3 存储桶以使用 MongoDB Stitch 上传音频文件(这里是mongo s3 docs 文档。按照说明操作并验证我的用户后,我在尝试上传所选文件时不断收到此错误:来自控制台的错误图像
在错误来自的第 119 行,我只是在运行 AWS 构建后发现了错误:
const aws = stitchClient.getServiceClient(AwsServiceClient.factory, "AWS");
convertAudioToBSONBinaryObject(file).then((result) => {
const audiofile = mongodb.db("data").collection("audiofile");
//now we need an instance of AWS service client
const key = `${stitchClient.auth.user.id}-${file.name}`;
// const key = `${stitchClient.auth.user.id}-${file.name}`;
const bucket = "myBucketName";
const url =
"http://" + bucket + ".s3.amazonaws.com/" + encodeURIComponent(key);
const args = {
ACL: "public-read",
Bucket: bucket,
ContentType: file.type,
Key: key,
Body: result,
// aws_service: "s3",
};
// building the request
const request = new AwsRequest.Builder()
.withService("s3")
.withAction("PutObject")
.withRegion("us-east-1")
.withArgs(args);
aws
.execute(request.build)
.then((result) => {
console.log(result);
console.log(url);
return audiofile.insertOne({
owner_id: stitchClient.auth.user.id,
url,
file: {
name: file.name,
type: file.type,
},
Etag: result.Etag,
ts: new Date(),
});
})
.then((result) => {
console.log("last result", result);
})
.catch((err) => {
console.log(err);
});
});
我的 s3 缝合规则如下所示:AWS s3 的缝合规则
所以在我看来,一切都是按照它的方式设置的,但是错误告诉我我没有传递所有需要的参数。我非常感谢有关如何解决此错误的任何想法。
PS如果我在这一行中将“AWS”更改为“AWS_S3”:
const aws = stitchClient.getServiceClient(AwsServiceClient.factory, "AWS");
错误消息更改为:
StitchServiceError {消息:“服务未找到:'AWS_S3'”,名称:“StitchServiceError”,errorCode:18,errorCodeName:“ServiceNotFound”,
Stitch 中的日志显示了这两个错误的信息:Stitch Logs
解决方案
答案是这一行中的一个简单错字:
aws
.execute(request.build)
.then((result)
build 是一个函数,所以我只需要调用它 - (request.build()).then((result)。问题已解决,谢谢大家!
推荐阅读
- jquery - 使用动态数据创建莫里斯线图
- concurrency - 为什么 ThreadLocal 使用哈希码,而不是像 netty FastThreadLocal 那样使用数组?
- c# - Xamarin - 如何将对象传递给事件处理程序
- firebase - 运行“cordova run android”时出现错误
- amazon-web-services - 如何在使用 AWS CDK 构建 cdk 时安装 lambda 函数的依赖项
- css - 如何在精灵中获取 SVG 图标的自动宽度?
- php - 如何解决有关 JQuery 日期选择器的问题?
- java - 应用 Proguard 后 Firebase google 登录将不起作用
- airflow - 调度程序重新启动后,气流创建重复的 SubDAG 运行
- css - Angular 中的延迟加载样式