Send arquvios to S3 IONIC

Asked

Viewed 42 times

0

I’m trying to use the plugin http://market.ionic.io/plugins/image-upload to try to upload the photos to S3, but I’m having a lot of problems, mainly that in the IOS it does not recognize the variable ImageUpload 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");
    });
  • 1

    You can add the code you are using to the question?

  • I added the code there

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.