【问题标题】:Using AWS Javascript SDK with NativeScript将 AWS Javascript SDK 与 NativeScript 结合使用
【发布时间】:2019-06-18 10:51:38
【问题描述】:

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

请有人告诉我是否可以将 AWS JS SDK 与 nativescript 一起使用。 如果是,怎么做?

谢谢。

【问题讨论】:

  • 我不确定 AWS,但您可以在 NativeScript 环境中使用任何 JavaScript 库/模块,只要它不依赖于任何浏览器/节点特定功能。

标签: aws-sdk nativescript


【解决方案1】:

是的,您可以将 AWS 开发工具包与 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');
    });

附:如果您没有身份池,则需要在 cognito 中创建一个身份池。

【讨论】:

  • 模块未找到:错误:无法解析“计时器”模块未找到:错误:无法解析“dgram”模块未找到:错误:无法解析“子进程”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-11
  • 2018-08-27
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
相关资源
最近更新 更多