iosamazon-web-servicesamazon-s3temenos-quantum

How do I upload an image from iOS app (built with Kony) to AWS S3 using aws-sdk for javascript?


I am using Kony Visualizer (a low code platorm) to build a mobile app (builds an iOS and Android native app) that can post images taken by the user to an s3 bucket. I am currently using the aws sdk for js (easy import into this low code platform) and am trying to use an s3.putObject call to push the image up. I have found that I can push the base64 string of the image's rawbytes to s3 storage from an Android device, but am unsuccessful in doing so from an iOS device. I have posted this on the Kony forum too at this link and will paste my code below. Also, I know the connection to s3 is working, because I am posting csv files to the same bucket in another part of my code.

AWS.config.update({
    accessKeyId: <accessKeyId>,
    secretAccessKey: <secretAccessKey>,
    region: <region>
});

var rawImg = this.view.Picture.rawBytes;
var b64img = kony.convertToBase64(rawImg);

var bucketImage = new AWS.S3();
var paramsImage = {
    Bucket: <bucket-name>,
    Key: "images/imageB64.jpg",
    ContentType: 'image/jpg',
    Body: b64img};

bucketImage.putObject(paramsImage, function(err,res){
    if (err) {
        alert(err);}
    else {
        alert('Success');
    }
});

Solution

  • I'm sure the FFI option would have worked, but I found that once I added the App Transport Security Settings -- Allow Arbitrary Loads - YES to my Info.plist in Xcode, and , these uploads started working. Apparently this uses http headers, which iOS doesn't automatically allow. I also had to add the following JSON to my infoplist_configuration.json file under my project in Kony Workspace: "NSAppTransportSecurity" : { "NSAllowsArbitraryLoads" : true }