Send files to S3 IONIC

0

I'm trying to use the link plugin to try to send the photos to S3, but I'm having a lot of problems , mainly that in tests in IOS it does not recognize the ImageUpload variable in the statement below var imageUpload = new ImageUpload ();

S3Uploader.js

var s3Uploader = (function () {

var s3URI = encodeURI("https://YOUR_S3_BUCKET.s3.amazonaws.com/"),
    policyBase64 = "YOUR_BASE64_ENCODED_POLICY_FILE",
    signature = "YOUR_BASE64_ENCODED_SIGNATURE",
    awsKey = 'YOUR_AWS_USER_KEY',
    acl = "public-read";

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

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

function upload(imageURI, fileName) {

    var deferred = $.Deferred(),
        ft = new FileTransfer(),
        options = new FileUploadOptions();

    options.fileKey = "file";
    options.fileName = fileName;
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;
    options.params = {
        "key": fileName,
        "AWSAccessKeyId": awsKey,
        "acl": acl,
        "policy": policyBase64,
        "signature": signature,
        "Content-Type": "image/jpeg"
    };

    ft.upload(imageURI, s3URI,
        function (e) {
            deferred.resolve(e);
        },
        function (e) {
            deferred.reject(e);
        }, options);

    return deferred.promise();

}

return {
    upload: upload
}

}());

Controller.js

s3Uploader.upload(solucaoItem.arquivo[i].arquivoUri, 'teste')
    .done(function () {
        alert("S3 upload succeeded");
    })
    .fail(function () {
        alert("S3 upload failed");
    });
    
asked by anonymous 01.08.2016 / 14:59

0 answers