mhartington / ama

Ask me anything!
5 stars 1 forks source link

Upload video capture to S3 #5

Closed idgm5 closed 8 years ago

idgm5 commented 8 years ago

Hello,

I'm trying to upload a video capture to my S3 Bucket, but I can't do it.

Maybe I need to configure my bucket, I already allowed POST / PUT / GET in my CORS configuration. I don't know if my policy need to be the same as the policy of my bucket.

Here my code:

'use strict';

app.controller('VideoCtrl', function($scope, $cordovaCapture, $state, $cordovaFileTransfer) {

$scope.record = function(){
var options = { limit: 1, duration: 8 };
$cordovaCapture.captureVideo(options).then(
function(videoData) {
var i, path, len;
var pathtogo;
var pathtogostring;
for (i = 0, len = videoData.length; i < len; i += 1) {
path = videoData[i].fullPath;
pathtogo = path.toString();
$scope.videos.$add(pathtogo);
};
},
$state.go('tab.photo-detail'),

  function(err) {
  }
);
var options = new FileUploadOptions();
options.fileKey="file";
var fileName = "capturedvideo.MOV";
options.fileName = fileName;
options.mimeType ="video/mov";
options.chunkedMode = false;

  var uri = encodeURI("https://<my bucket>.amazonaws.com/");

  var policyDoc = "js/signing-util.js";
  var signature = "js/signing-util.js";
  var params = {
    "key": "file",
    "AWSAccessKeyId": "<MY AWS Key>",
    "acl": "public-read",
    "policy": policyDoc,
    "signature": signature,
    "Content-Type": "video/mov"
  };
  options.params = params;

  $cordovaFileTransfer.upload(videoData[i].fullPath, uri, options)
            .then(function(result) {
                console.log("SUCCESS: " + JSON.stringify(result.response));
            }, function(err) {
                console.log("ERROR: " + JSON.stringify(err));
            }, function(progress) {
                // constant progress updates
            });
};
});

My signature / policy doc is this:

var crypto = require('crypto'),
secret = "",
policy,
policyBase64,
signature;

policy = {
"expiration": "2050-12-31T12:00:00.000Z",
"conditions": [
{"bucket": ""},
["starts-with", "$key", ""],
{"acl": 'public-read'},
["starts-with", "$Content-Type", ""],
["content-length-range", 0, 5242880000]
]
};

policyBase64 = new Buffer(JSON.stringify(policy), 'utf8').toString('base64');
console.log("Policy Base64:");
console.log(policyBase64);

signature = crypto.createHmac('sha1', secret).update(policyBase64).digest('base64');
console.log("Signature:");
console.log(signature);

Is something wrong with my code?

PLUS: I use the default cordova-platform iOS @3.9.2 but every time I got access to my camera on device (iPhone 6 - iOS 9) I receive this error: Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

Is only a warning issue or is not capturing the video?

Thanks.