Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 230945

Ionic camera upload AWS3 - File transfer deprecated

$
0
0

It’s the third topics I ask and I not receive an aswer or a tips. So this is my way to solve my problem. I hope I will help someone else in same condition.

I first follow this guide online to set amazon bucket for IAM users: https://www.youtube.com/watch?v=Oc69SEtbM_U

I found that my problem was to install first the require word, and solved it by adding some code to tsconfig.json:

    "types": ["node"],
    "typeRoots": [
      "node_modules/@types"
    ]

inside complireOptions. If it still does not work try to type : npm install @types/node --save -dev
and then in your page declare require like :

declare var require: any;
require('aws-sdk');

Then I configure AWS inside my costructor and create a function to upload:

    let BUCKET_NAME = 'name_bucket';
    const IAM_USER_KEY = 'xxxxxxxxxxxx';
    const IAM_USER_SECRET = 'xxxxxxxxxxxxxxxx';

    AWS.config = new AWS.Config();
    AWS.config.accessKeyId = IAM_USER_KEY;
    AWS.config.secretAccessKey = IAM_USER_SECRET;
    AWS.config.region = "region";

This is my function:

    let date = new Date();
    let current_seconds = date.getSeconds();

    var bufferValue = this.dataURItoBlob(file);
    let bucket = new AWS.S3();
    bucket.createBucket(function () {
      var params = {
        Bucket: 'xxxxxxx',
        Key: 'name'+current_seconds+'.png',
        Body:  bufferValue ,
        ContentType: 'image/png',
        ACL: 'public-read'
      };
      bucket.upload(params, function (err, data) {
        if (err) {
          console.log('error in callback');
          console.log(err);
        }
        console.log('success');
        console.log(data);
      });
    });

BufferValue is the image base64 in blob passed by camera to dataURItoBlob function.

I hope I was clear.


Viewing all articles
Browse latest Browse all 230945

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>