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');
});
1 回答
是的,您可以将AWS SDK与NativeScript一起使用 . 我用它来上传文件到S3 . 您需要使用它来安装它
文件上传到AWS S2示例在组件文件中,导入它
附:如果您没有Idendity池,则需要在cognito中创建一个Idendity池 .