Angular 2 / Javascript AWS S3 SDK - 中止上传onClick

时间:2017-12-05 10:55:40

标签: javascript angular amazon-s3

我在Angular 2工作,并通过javascript AWS S3 SDK实现了S3上传。我的问题是如何通过点击按钮中止上传?

到目前为止,我已尝试过以下但我得到一个'未定义不是对象(评估'this.bucket.abort.bind')

我的上传功能:

upload(): void {
AWS.config.update({
    region: AWSREGION,
    credentials: new AWS.CognitoIdentityCredentials(
        {
            IdentityPoolId: AWSIDENTITYPOOLID,
            IdentityId: obj.IdentityId,
            Logins: {
                'cognito-identity.amazonaws.com': obj.Token
            }
        }
    )
});
this.awsToken = obj.Token;
// set bucket 
this.bucket = new AWS.S3({params: {Bucket: 'myBucket'}});
// Upload to S3
          this.bucket.putObject(params, (err, data) => {
            if (err) {
                console.log('AWS Error', err);      
            } else {
              // Success 
              console.log('Success');
            }
           });  
}

我的取消按钮

 cancel(): void {

    this.bucket.abort.bind(this.bucket);
  }

1 个答案:

答案 0 :(得分:0)

以下结束工作:

upload(): void {
AWS.config.update({
    region: AWSREGION,
    credentials: new AWS.CognitoIdentityCredentials(
        {
            IdentityPoolId: AWSIDENTITYPOOLID,
            IdentityId: obj.IdentityId,
            Logins: {
                'cognito-identity.amazonaws.com': obj.Token
            }
        }
    )
});
this.awsToken = obj.Token;
// set bucket 
this.bucket = new AWS.S3({params: {Bucket: 'myBucket'}});
// Set request
this.request = this.bucket.putObject(params);   
// Upload to S3
          this.request.send((err, data) => {
            if (err) {
                console.log('AWS Error', err);      
            } else {
              // Success 
              console.log('Success');
            }
           });  
}

我的取消按钮

 cancel(): void {

    this.request.abort();
  }