首页 文章

将AWS Javascript SDK与NativeScript一起使用

提问于
浏览
0

我打算使用Nativescript构建一个应用程序 . 但是,我想在应用程序架构中集成AWS服务 .

请问,有人可以告诉我是否可以将AWS JS SDk与nativescript一起使用 . 如果有,怎么样?

谢谢 .

1 回答

  • 0

    是的,您可以将AWS SDK与NativeScript一起使用 . 我用它来上传文件到S3 . 您需要使用它来安装它

    npm i aws-sdk
    

    文件上传到AWS S2示例在组件文件中,导入它

    import * as AWS from 'aws-sdk';
    
    const AWSService = AWS;
        const region = 'Your_Region_name';
        this.bucketName = 'bucketName ';
        const IdentityPoolId = 'IdentityPoolId';
    
        // Configures the AWS service and initial authorization
        AWSService.config.update({
          region: region,
          credentials: new AWSService.CognitoIdentityCredentials({
            IdentityPoolId: IdentityPoolId
          })
        });
    
        // adds the S3 service, make sure the api version and bucket are correct
        this.s3 = new AWSService.S3({
          apiVersion: '2006-03-01',
          params: { Bucket: this.bucketName }
        });
    this.s3.upload({ Key: 'test/' + file.name, Bucket: this.bucketName, Body: file, ACL: 'public-read' }, function (err, data) {
          if (err) {
            console.log(err, 'there was an error uploading your file');
          }
          console.log('upload done');
        });
    

    附:如果您没有Idendity池,则需要在cognito中创建一个Idendity池 .

相关问题