0.0.2 • Published 3 years ago

@avergara/nativescript-aws-sdk v0.0.2

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
3 years ago

NativeScript AWS SDK

npm npm Build Status

Installation

NativeScript 7x

  • ns plugin add @avergara/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

MethodDefaultTypeDescription
createDownload(options: S3DownloadOptions)numberCreates a task it returns the id of the task
createUpload(options: S3UploadOptions)numberCreates a task it returns the id of the task
resume(id: number)voidResumes a task.
cancel(id: number)voidCancels a task.
pause(id: number)voidPauses a task.

Example Image

IOSAndroid
IOSAndroid