结合使用AWS Javascript SDK和NativeScript [英] Using AWS Javascript SDK with NativeScript
问题描述
我打算使用Nativescript来构建应用程序.但是,我想将AWS服务集成到应用程序架构中.
I'm planning to build an app using Nativescript. However, I want to integrate AWS services in the app architecture.
请,有人可以告诉我是否可以将AWS JS SDk与nativescript一起使用. 如果是,怎么办?
Please, can someone tell me whether I can use AWS JS SDk with nativescript or not. If yes, how?
谢谢.
推荐答案
是的,您可以将AWS开发工具包SDK与NativeScript一起使用.我正在使用它将文件上传到S3.您需要使用
Yes, you can use AWS SDK with NativeScript. I am using it to upload files to S3. You need to install it using
npm i aws-sdk
文件上传到AWS S2示例 在您的组件文件中,将其导入
File upload to AWS S2 example In your component file, import it
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');
});
P.S.如果您没有,则需要在Cognito中创建一个Idendity池.
P.S. You need to create a Idendity pool in cognito if you don't have one.
这篇关于结合使用AWS Javascript SDK和NativeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!