beek
beek

Reputation: 3750

Ionic Upload Video to S3

I'm attempting to use this to upload videos http://market.ionic.io/plugins/image-upload

I know the file paths of the videos (they're on cameras I can access via HTTP), I'm trying to work out how to use something like this to get these videos onto S3.

I get that I can't pass the file path to this function, and it needs to be an actual file as per the directive.

How do I copy a large video file into an Javascript variable to upload as a file?

  var imageUploader = new ImageUploader();
  scene.videoFiles.forEach(function(videoFile) {
    imageUploader.push(videoFile, function (data) {
      console.log('File uploaded Successfully', videoFile, data);
      $scope.uploadUri = data.url;
      $scope.$digest();

    });
  })};

Upvotes: 1

Views: 1106

Answers (1)

Niroshan Ranapathi
Niroshan Ranapathi

Reputation: 3047

you can use $cordovaFile and aws java script-sdk for upload file (video ) to aws-s3 bucket. This is the sample code for upload video to s3 bucket.

var uploadFile = function (file_name,file_path) {
            var deferred = $q.defer();
            $cordovaFile.readAsArrayBuffer(file_name,file_path)
                .then(function (success) {
                    AWS.config.region = 'eu-west-1';
                    AWS.config.update({
                        accessKeyId: 'ACCESS-KEY',
                      secretAccessKey:'SECRET-KEY'
                    });
                    var bucket = new AWS.S3({
                        params: {
                            Bucket: 'Bucket-NAME'
                        }
                    });
                    var params = {
                        Key: "uploads/"+file_name,
                        Body: success
                    };

                    bucket.upload(params).on('httpUploadProgress',function(evt){
                        $scope.uploading = true;
                        $scope.progress = parseInt((evt.loaded*100)/ evt.total);
                        console.log("Uploaded :: " + $scope.progress);
                        $scope.$apply();
                    }).send(function (err, data) {
                        $scope.uploading = false;
                        $scope.$apply();
                        deferred.resolve(data);

                    });
                    $scope.i++;

                }, function (error) {
                    deferred.reject(error);
                });
            return deferred.promise;
        };

Upvotes: 1

Related Questions