【发布时间】:2021-01-04 15:37:12
【问题描述】:
我正在尝试将 base64 图像从 Angular 应用程序上传到 Amazon S3 存储桶。以下是我正在使用的代码。
uploadAssets(base64File, assetType, fileName, file) {
const AWSService = AWS;
const region = ""
const bucketName = "";
const identityPoolId = "";
const accessKeyId = "";
const secretAccessKey = "";
AWSService.config.update({
region: region,
accessKeyId: accessKeyId,
secretAccessKey: secretAccessKey,
credentials: new AWSService.CognitoIdentityCredentials({
IdentityPoolId: identityPoolId
})
});
const s3 = new AWSService.S3({
apiVersion: '',
});
var objKey = bucketName+ "/" + fileName;
var params = {
Key: objKey,
ContentType: file.type,
Bucket: bucketName,
Body: base64File,
ContentEncoding: 'base64',
ACL: 'public-read'
};
s3.upload(params, function (err, data) {
if (err) {
console.log(err, 'there was an error uploading your file');
} else {
console.log(data);
}
});
}
由于某种原因,我收到以下错误
TypeError: 无法读取未定义的属性“byteLength”
我在这里遗漏了什么吗?
【问题讨论】:
-
错误来自哪里?它来自 s3 库吗?是来自网络请求吗?它在你的代码中吗?听起来您正在将未定义的值传递给期望流的东西。
-
错误来自 s3 库。 .upload 函数收到错误。我在 Node.js 上做过类似的事情,但是在 Angular 上我收到一个错误
-
你修好了吗?我也有同样的问题。
标签: angular amazon-web-services amazon-s3