![](/img/trans.png)
[英]Got TS 2739 error while returning value from promise. Type 'Promise<any>' is missing the following properties from type
[英]Type 'S3' is missing the following properties from type 'S3Client': destroy, middlewareStack, sendts(2739)
我在使用 typescript 處理節點后端時遇到此錯誤,這是用於將文件上傳到 aws S3 的 function。 我是使用 typescript 的新手,所以任何人都可以幫助我。
import AWS from "aws-sdk";
import multer from "multer";
import multerS3 from "multer-s3";
let S3 = new AWS.S3({
accessKeyId: process.env.AWS_KEY,
secretAccessKey: process.env.AWS_SECRET
})
const upload = multer({
storage: multerS3({
s3:S3, //error here
bucket: 'bucket-name',
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname });
},
key: function (req, file, cb) {
cb(null, Date.now().toString())
}
})
})
export { upload }
所以問題是您正在使用 s3 ask 的版本 2 而不是 v3 sdk: @aws-sdk/client-s3
創建一個 s3 客戶端。 aws-sdk
提供版本 2 客戶端, @aws-sdk/client-s3
是 V3 javascript SDK 的一部分。
確保安裝npm i @aws-sdk/client-s3
。
您可以在此處閱讀有關客戶端 s3 sdk 的信息
import AWS from "aws-sdk";
import { S3Client } from '@aws-sdk/client-s3';
import multer from "multer";
import multerS3 from "multer-s3";
const s3Config = new S3Client({
region: 'us-west-1',
credentials:{
accessKeyId:'',
secretAccessKey:''
}
})
const upload = multer({
storage: multerS3({
s3: s3Config,
bucket: 'bucket-name',
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname });
},
key: function (req, file, cb) {
cb(null, Date.now().toString())
}
})
})
export { upload }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.