【问题标题】:Issue with uploading Image to Amazon S3 Bucket from Angular app从 Angular 应用程序将图像上传到 Amazon S3 存储桶的问题
【发布时间】: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


【解决方案1】:

当我将 secretAccessKey 更改为 secretKey 时,它对我有用

【讨论】:

  • 这个想法从何而来?
猜你喜欢
  • 1970-01-01
  • 2014-12-19
  • 1970-01-01
  • 2021-12-15
  • 2023-02-04
  • 2020-12-30
  • 1970-01-01
  • 2019-06-14
  • 2017-08-30
相关资源
最近更新 更多