This should help you get started. Please forgive my pseudo code. Feel free to edit it as needed.
The device saves the image to disk:
function takePicture(urlCallback){
let options = {
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
encodingType: Camera.EncodingType.JPG
};
navigator.camera.getPicture(urlCallback, onFail, options);
function onFail(message) {
alert('Failed because: ' + message);
}
}
Get the image from disk as blob:
function getImageAsBlob(url, blobCallback) {
var xhr = new XMLHttpRequest();
xhr.open( "GET", url, true );
xhr.responseType = "arraybuffer";
xhr.onload = function( ev ) {
var arrayBufferView = new Uint8Array( this.response );
var blob = new Blob( [ arrayBufferView ], { type: "image/jpeg" } );
blobCallback(blob);
};
xhr.send();
}
Download blob on S3:
function uploadToS3(blob, callback) {
let AWS = require('aws-sdk');
AWS.config = new AWS.Config();
AWS.config.accessKeyId = 'noway';
AWS.config.secretAccessKey = 'jose';
AWS.config.region = 'us-east-2';
let s3 = new AWS.S3();
let options = { Bucket: 'iamkule/f1/f2', Key: 'myfile.jpg', Body: blob };
s3.upload(options, callback);
}
Putting it all together:
takePicture(function(url){
getImageAsBlob(url, function(blob){
uploadToS3(blob, function (err, data) {
if (data) console.log('yay!');
});
});
});
S3 . .
!