aws-sdk - 将 AWS Javascript SDK 与 NativeScript 结合使用
问题描述
我打算使用 Nativescript 构建一个应用程序。但是,我想将 AWS 服务集成到应用程序架构中。
请有人告诉我是否可以将 AWS JS SDK 与 nativescript 一起使用。如果是,如何?
谢谢你。
解决方案
是的,您可以将 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');
});
PS 如果您没有身份池,则需要在 cognito 中创建一个身份池。
推荐阅读
- mysql - 我将如何更新此 MySQL 查询以获取从开始、停止、暂停和恢复事件的总经过时间
- azure - Azure:开发测试实验室中许多 VM 的相同资源组
- python - 如何在 Web 应用程序的 Docker 映像中安装和启动 CouchDB 服务器?
- url - 重写 URL 规则
- raspberry-pi - Raspberry Pi 上是否有适用于 youtube-dl 和 omxplayer 的最小电视 GUI?
- regex - 正则表达式 [AZ]{2,3}\\d+ 是什么意思
- sql - Oracle 对多个窗口的第一次和最后一次观察
- html - 用户登录后,如何在每个页面上隐藏/禁用注册和登录按钮?
- jquery - 对 Flask 服务的 Ajax GET 请求失败并返回奇怪的空对象,但粘贴到地址栏时相同的 URL 有效
- c++ - IPOPT 不服从约束但在使用 CppAD 时不记录违规