nativescript-aws-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

NativeScript AWS SDK

npm npm Build Status

Installation

tns plugin add nativescript-aws-sdk

Usage

Android

Add the following services in the 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

Method Default Type Description
createDownload(options: S3DownloadOptions) number Creates a task it returns the id of the task
createUpload(options: S3UploadOptions) number Creates a task it returns the id of the task
resume(id: number) void Resumes a task.
cancel(id: number) void Cancels a task.
pause(id: number) void Pauses a task.

Example Image

IOS Android
IOS Android

Package Sidebar

Install

npm i nativescript-aws-sdk

Weekly Downloads

1

Version

0.0.4

License

Apache-2.0

Unpacked Size

407 kB

Total Files

19

Last publish

Collaborators

  • triniwiz