如何将任何文件上传到角度为4的s3存储桶

时间:2017-11-21 18:22:01

标签: angular file-upload amazon-s3

是否有任何特定的方法将文件上传到角度为4的s3存储桶。我找到了一些像file upload to s3 with angular这样的解决方案,但是npm包不存在。还有其他任何简单的角度方式4.希望你的帮助。

1 个答案:

答案 0 :(得分:0)

 imgattached(img) {
    AWS.config.region = 'Enter your region'; // 1. Enter your region
    var bucketName = 'Enter your bucket name'; // Enter your bucket name
    AWS.config.credentials = new AWS.CognitoIdentityCredentials({
      IdentityPoolId: 'your identity pool' // 2. Enter your identity pool
    });

    var that = this;
    var bucket = new AWS.S3({
      params: {
        Bucket: bucketName
      }
    });
    var a = Attachment.target.files;
    var file = a[0];

        console.log(file.name);
        if (file) {
          var objKey = file.name;
          var params = {
            Key: objKey,
            ContentType: file.type,
            Body: file,
            ACL: 'public-read'
          };

          bucket.upload(params, function (err, data) {
            if (data) {
            console.log(data.Location);//done
            }
          });
        }

  }

/////////////////的Html ////////////////////