npm i --save nativescript-aws-sdk
- 版本:0.0.4
- GitHub:
- NPM: https://npmjs.net.cn/package/nativescript-aws-sdk
- 下载量
- 昨天: 0
- 上周: 2
- 上个月: 11
NativeScript AWS SDK
安装
tns plugin add nativescript-aws-sdk
用法
Android
在 app/App_Resources/Android/AndroidManifest.xml 中添加以下服务
<manifest ... >
<application ... >
...
<service android:name= "com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" />
</application>
</manifest>
TypeScript
S3
import { S3 } from 'nativescript-aws-sdk';
S3.init({ endPoint: '', accessKey: '', secretKey: '', type: 'static' }); // <= Try calling this before the app starts
import { S3 } from 'nativescript-aws-sdk';
const s3 = new S3();
const imageUploaderId = s3.createUpload({
file: '~/assets/hulk_wolverine_x_men.jpg',
bucketName: 'yaychat',
key: `ns_${isIOS ? 'ios' : 'android'}_hulk_wolverine_x_men.jpg`,
acl: 'public-read',
completed: (error, success) => {
if (error) {
console.log(`Download Failed :-> ${error.message}`);
}
if (success) {
console.log(`Download Complete :-> ${success.path}`);
}
},
progress: progress => {
console.log(`Progress : ${progress.value}`);
}
});
s3.pause(imageUploaderId);
s3.resume(imageUploaderId);
s3.cancel(imageUploaderId);
JavaScript
const S3 = require('nativescript-aws-sdk').S3;
S3.S3.init({ endPoint: '', accessKey: '', secretKey: '', type: 'static' }); // <= Try calling this before the app starts
const imageUploaderId = s3.createUpload({
file: '~/assets/hulk_wolverine_x_men.jpg',
bucketName: 'yaychat',
key: `ns_${isIOS ? 'ios' : 'android'}_hulk_wolverine_x_men.jpg`,
acl: 'public-read',
completed: (error, success) => {
if (error) {
console.log(`Download Failed :-> ${error.message}`);
}
if (success) {
console.log(`Download Complete :-> ${success.path}`);
}
},
progress: progress => {
console.log(`Progress : ${progress.value}`);
}
});
s3.pause(imageUploaderId);
s3.resume(imageUploaderId);
s3.cancel(imageUploaderId);
API
S3
方法 | 默认 | 类型 | 描述 |
---|---|---|---|
createDownload(options: S3DownloadOptions) | number |
创建一个任务并返回任务的 ID | |
createUpload(options: S3UploadOptions) | number |
创建一个任务并返回任务的 ID | |
resume(id: number) | void |
恢复任务。 | |
cancel(id: number) | void |
Cancels a task. | |
pause(id: number) | void |
Pauses a task. |
示例图片
IOS | Android |
---|---|