[AWS S3 Extension] How to use file path (mobile local storage file) instead of binary data?

[AWS S3 Extension] How to use file path (mobile local storage file) instead of binary data?

  
Forge Component
(2)
Published on 2017-12-01 by Joao Oliveira
2 votes
Published on 2017-12-01 by Joao Oliveira

Hello,

I'm developing a mobile App that records a video and after storing it on the mobile local memory it must be uploaded to a s3 bucket.

Currently I'm using the extension to store documents in s3 bucket based on the binary data that I use as input of the "TransferUtilityUpload" with success. However, since there are some limitations on the maximum binary data that I can save on the database/use as input (máx. about 20MB), I would need to use the FilePath (something like file:///storage/emulated/0/DCIM/Camera/VID20180316_102839.mp4) instead of binary data to directly send the file from the local storage of the phone to the s3 bucket.


Based on the information and API from Amazon it should be possible, but if the TransferUtilityUpload is a server action, how can the function use the local storage of the phone?  

Hi Andre,


One way is to use a Cordova plugin to interact directly with S3 from the phone, like the following:

https://plugins.telerik.com/cordova/plugin/amazon-aws


There is a training lesson that shows how to use Cordova Native Plugins:

https://www.outsystems.com/learn/lesson/1185/using-cordova-native-plugins/


Cheers,

Renato


Andre Paula wrote:

Hello,

I'm developing a mobile App that records a video and after storing it on the mobile local memory it must be uploaded to a s3 bucket.

Currently I'm using the extension to store documents in s3 bucket based on the binary data that I use as input of the "TransferUtilityUpload" with success. However, since there are some limitations on the maximum binary data that I can save on the database/use as input (máx. about 20MB), I would need to use the FilePath (something like file:///storage/emulated/0/DCIM/Camera/VID20180316_102839.mp4) instead of binary data to directly send the file from the local storage of the phone to the s3 bucket.


Based on the information and API from Amazon it should be possible, but if the TransferUtilityUpload is a server action, how can the function use the local storage of the phone?  



Renato Torres wrote:

Hi Andre,


One way is to use a Cordova plugin to interact directly with S3 from the phone, like the following:

https://plugins.telerik.com/cordova/plugin/amazon-aws


There is a training lesson that shows how to use Cordova Native Plugins:

https://www.outsystems.com/learn/lesson/1185/using-cordova-native-plugins/


Cheers,

Renato


Hey Renato,

Thanks for the fast reply. 

However I'm having a problem that I dont undertand just to list the objects. The error says "cannot read property 'config' of undefined" but I think I'm importing correctly the plugin, like I did in others like the https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-media-capture/  and doing what its said.

On the extensibility options:

{
    "plugin":
    {
        "identifier": "aws-sdk",
        "url": "https://github.com/Telerik-Verified-Plugins/Amazon-AWS",
        "variables": [{
            "name": "ACCESS_KEY",
            "value": "<my acess key>"
        },
        {
            "name": "SECRET_KEY",
            "value": "<my secret key>"
        }]
    }
}


On the javascript function (list objects):


Do you know whats the problem? I think the var AWS = require('aws-sdk'); is not working, but I don´t understand why.

Also, don´t understand how can I use the filePath of the mobile to upload directly, since there isnt any option to do that on the API, only binary data.


Solution

Hi Andre,


I did the following:


1. Create plugin with this conf:

{
    "plugin" :{
        "url": "https://github.com/Telerik-Verified-Plugins/Amazon-AWS.git#1.1.0",
       
        "variables": [
               {
                    "name": "ACCESS_KEY",
                    "value": "YOUR ACCESS KEY HERE"
                },
                {
                    "name": "SECRET_KEY",
                    "value": "YOUR SECRET KEY HERE"
                }            
        ]
    }
}


2. Created a demo app with reference to the previous plugin with the following "OnApplicationReady"



3. Created a screen to list the files on a button click:


4. Configured CORS on bucket

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>GET</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>


5. Uploaded a file to the bucket and test it on a phone


I didn't try to upload a file but the connection to S3 was OK.


Hope it can help.


Cheers,

Renato


Andre Paula wrote:

Renato Torres wrote:

Hi Andre,


One way is to use a Cordova plugin to interact directly with S3 from the phone, like the following:

https://plugins.telerik.com/cordova/plugin/amazon-aws


There is a training lesson that shows how to use Cordova Native Plugins:

https://www.outsystems.com/learn/lesson/1185/using-cordova-native-plugins/


Cheers,

Renato


Hey Renato,

Thanks for the fast reply. 

However I'm having a problem that I dont undertand just to list the objects. The error says "cannot read property 'config' of undefined" but I think I'm importing correctly the plugin, like I did in others like the https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-media-capture/  and doing what its said.

On the extensibility options:

{
    "plugin":
    {
        "identifier": "aws-sdk",
        "url": "https://github.com/Telerik-Verified-Plugins/Amazon-AWS",
        "variables": [{
            "name": "ACCESS_KEY",
            "value": "<my acess key>"
        },
        {
            "name": "SECRET_KEY",
            "value": "<my secret key>"
        }]
    }
}


On the javascript function (list objects):


Do you know whats the problem? I think the var AWS = require('aws-sdk'); is not working, but I don´t understand why.

Also, don´t understand how can I use the filePath of the mobile to upload directly, since there isnt any option to do that on the API, only binary data.




Solution

Many thanks Renato, the solution above worked.