简体   繁体   English

StitchServiceError “aws: ”aws_service“ 是必需的字符串”, errorCodeName: InvalidParameter

[英]StitchServiceError “aws: ”aws_service“ is a required string”, errorCodeName: InvalidParameter

I'm setting up AWS S3 bucket to upload audio files to using MongoDB Stitch (here are the docs mongo s3 docs . After following the instructions and authenticating my user I keep geting this error when trying to upload the selected file: error image from console我正在设置 AWS S3 存储桶以使用 MongoDB Stitch 上传音频文件(这里是文档mongo s3 文档。按照说明操作并验证我的用户后,我在尝试上传所选文件时不断收到此错误:来自控制台的错误图像

On line 119 where the error is coming from I'm just catching the error after running AWS build:在错误来自的第 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);
    });
});

My Stitch rule for s3 looks like this: Stitch rule for AWS s3我的 s3 缝合规则如下所示: AWS s3 的缝合规则

So it seems to me that everything is set up the way it's inteded to, but the error tells me I'm not passing all the needed args.所以在我看来,一切都是按照它的方式设置的,但是错误告诉我我没有传递所有需要的参数。 I'd really appreciate any thoughts on how to fix this error.我非常感谢有关如何解决此错误的任何想法。

PS If I change "AWS" to "AWS_S3" in this line: const aws = stitchClient.getServiceClient(AwsServiceClient.factory, "AWS"); PS如果我在这一行中将“AWS”更改为“AWS_S3”: const aws = stitchClient.getServiceClient(AwsServiceClient.factory, "AWS"); The error message changes to this:错误消息更改为:

StitchServiceError {message: "service not found: 'AWS_S3'", name: "StitchServiceError", errorCode: 18, errorCodeName: "ServiceNotFound", StitchServiceError {消息:“服务未找到:'AWS_S3'”,名称:“StitchServiceError”,errorCode:18,errorCodeName:“ServiceNotFound”,

And the log in Stitch shows this for information for both errors: Stitch Logs Stitch 中的日志显示了这两个错误的信息: Stitch Logs

The answer to this is a simple typo in this line:答案是这一行中的一个简单错字:

aws.execute(request.build).then((result)

build is a function so I just needed to call it - (request.build()).then((result). Issue solved, thanks all! build 是 function 所以我只需要调用它 - (request.build()).then((result)。问题已解决,谢谢大家!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM