![](/img/trans.png)
[英][StitchServiceError: Error: ObjectId in must be a single string of 12 bytes or a string of 24 hex characters]
[英]StitchServiceError “aws: ”aws_service“ is a required string”, errorCodeName: InvalidParameter
我正在設置 AWS S3 存儲桶以使用 MongoDB Stitch 上傳音頻文件(這里是文檔mongo s3 文檔。按照說明操作並驗證我的用戶后,我在嘗試上傳所選文件時不斷收到此錯誤:來自控制台的錯誤圖像
在錯誤來自的第 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 是 function 所以我只需要調用它 - (request.build()).then((result)。問題已解決,謝謝大家!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.