Dynamically provide awsconfiguration while uploading files using TransferUtility












0















Current Implementation



I have implemented file upload functionality using AWS Mobile SDK and according to their documentation, we have to store an awsconfiguration.json file (this file contains CognitoIdentity,IdentityManager & S3TransferUtility) and we create an instance of TransferUtility like this for uploading :



TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
.s3Client(new AmazonS3Client(AWSMobileClient.getInstance()))
.build();


This implementation works great when we have just one AWS Instance



Required Implementation



I have a requirement where i have to implement this for more than one AWS Instance. To explain better, we have more than one AWS account for different clients and each account will have their own s3 bucket.



Now i have to upload files based on the type of client i logged in within my app. This means that their awsconfiguration.json file will be different for each client.



Question



Is there any method by which i can dynamically generate awsconfiguration.json or better yet, pass values for fields like CognitoIdentity & S3TransferUtility when uploading file?










share|improve this question























  • You required all the values from awsconfiguration.json on your end??

    – Savin Sharma
    Nov 26 '18 at 11:17











  • yeah atleast CognitoIdentity & S3TransferUtility and their sub fields are needed

    – Ganesh K
    Nov 26 '18 at 11:22











  • You can manually configure your aws without the json file as well. Which you can make dynamic for your multiple accounts.

    – Savin Sharma
    Nov 26 '18 at 11:26











  • @SavinSharma If that is possible, can you please post the code snippet or share a link where i can find this solution?

    – Ganesh K
    Nov 26 '18 at 11:27











  • I have shared a code snippet which I have used for my aws upload part.

    – Savin Sharma
    Nov 26 '18 at 11:53
















0















Current Implementation



I have implemented file upload functionality using AWS Mobile SDK and according to their documentation, we have to store an awsconfiguration.json file (this file contains CognitoIdentity,IdentityManager & S3TransferUtility) and we create an instance of TransferUtility like this for uploading :



TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
.s3Client(new AmazonS3Client(AWSMobileClient.getInstance()))
.build();


This implementation works great when we have just one AWS Instance



Required Implementation



I have a requirement where i have to implement this for more than one AWS Instance. To explain better, we have more than one AWS account for different clients and each account will have their own s3 bucket.



Now i have to upload files based on the type of client i logged in within my app. This means that their awsconfiguration.json file will be different for each client.



Question



Is there any method by which i can dynamically generate awsconfiguration.json or better yet, pass values for fields like CognitoIdentity & S3TransferUtility when uploading file?










share|improve this question























  • You required all the values from awsconfiguration.json on your end??

    – Savin Sharma
    Nov 26 '18 at 11:17











  • yeah atleast CognitoIdentity & S3TransferUtility and their sub fields are needed

    – Ganesh K
    Nov 26 '18 at 11:22











  • You can manually configure your aws without the json file as well. Which you can make dynamic for your multiple accounts.

    – Savin Sharma
    Nov 26 '18 at 11:26











  • @SavinSharma If that is possible, can you please post the code snippet or share a link where i can find this solution?

    – Ganesh K
    Nov 26 '18 at 11:27











  • I have shared a code snippet which I have used for my aws upload part.

    – Savin Sharma
    Nov 26 '18 at 11:53














0












0








0








Current Implementation



I have implemented file upload functionality using AWS Mobile SDK and according to their documentation, we have to store an awsconfiguration.json file (this file contains CognitoIdentity,IdentityManager & S3TransferUtility) and we create an instance of TransferUtility like this for uploading :



TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
.s3Client(new AmazonS3Client(AWSMobileClient.getInstance()))
.build();


This implementation works great when we have just one AWS Instance



Required Implementation



I have a requirement where i have to implement this for more than one AWS Instance. To explain better, we have more than one AWS account for different clients and each account will have their own s3 bucket.



Now i have to upload files based on the type of client i logged in within my app. This means that their awsconfiguration.json file will be different for each client.



Question



Is there any method by which i can dynamically generate awsconfiguration.json or better yet, pass values for fields like CognitoIdentity & S3TransferUtility when uploading file?










share|improve this question














Current Implementation



I have implemented file upload functionality using AWS Mobile SDK and according to their documentation, we have to store an awsconfiguration.json file (this file contains CognitoIdentity,IdentityManager & S3TransferUtility) and we create an instance of TransferUtility like this for uploading :



TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.awsConfiguration(AWSMobileClient.getInstance().getConfiguration())
.s3Client(new AmazonS3Client(AWSMobileClient.getInstance()))
.build();


This implementation works great when we have just one AWS Instance



Required Implementation



I have a requirement where i have to implement this for more than one AWS Instance. To explain better, we have more than one AWS account for different clients and each account will have their own s3 bucket.



Now i have to upload files based on the type of client i logged in within my app. This means that their awsconfiguration.json file will be different for each client.



Question



Is there any method by which i can dynamically generate awsconfiguration.json or better yet, pass values for fields like CognitoIdentity & S3TransferUtility when uploading file?







android amazon-s3 aws-sdk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 26 '18 at 10:26









Ganesh KGanesh K

11511




11511













  • You required all the values from awsconfiguration.json on your end??

    – Savin Sharma
    Nov 26 '18 at 11:17











  • yeah atleast CognitoIdentity & S3TransferUtility and their sub fields are needed

    – Ganesh K
    Nov 26 '18 at 11:22











  • You can manually configure your aws without the json file as well. Which you can make dynamic for your multiple accounts.

    – Savin Sharma
    Nov 26 '18 at 11:26











  • @SavinSharma If that is possible, can you please post the code snippet or share a link where i can find this solution?

    – Ganesh K
    Nov 26 '18 at 11:27











  • I have shared a code snippet which I have used for my aws upload part.

    – Savin Sharma
    Nov 26 '18 at 11:53



















  • You required all the values from awsconfiguration.json on your end??

    – Savin Sharma
    Nov 26 '18 at 11:17











  • yeah atleast CognitoIdentity & S3TransferUtility and their sub fields are needed

    – Ganesh K
    Nov 26 '18 at 11:22











  • You can manually configure your aws without the json file as well. Which you can make dynamic for your multiple accounts.

    – Savin Sharma
    Nov 26 '18 at 11:26











  • @SavinSharma If that is possible, can you please post the code snippet or share a link where i can find this solution?

    – Ganesh K
    Nov 26 '18 at 11:27











  • I have shared a code snippet which I have used for my aws upload part.

    – Savin Sharma
    Nov 26 '18 at 11:53

















You required all the values from awsconfiguration.json on your end??

– Savin Sharma
Nov 26 '18 at 11:17





You required all the values from awsconfiguration.json on your end??

– Savin Sharma
Nov 26 '18 at 11:17













yeah atleast CognitoIdentity & S3TransferUtility and their sub fields are needed

– Ganesh K
Nov 26 '18 at 11:22





yeah atleast CognitoIdentity & S3TransferUtility and their sub fields are needed

– Ganesh K
Nov 26 '18 at 11:22













You can manually configure your aws without the json file as well. Which you can make dynamic for your multiple accounts.

– Savin Sharma
Nov 26 '18 at 11:26





You can manually configure your aws without the json file as well. Which you can make dynamic for your multiple accounts.

– Savin Sharma
Nov 26 '18 at 11:26













@SavinSharma If that is possible, can you please post the code snippet or share a link where i can find this solution?

– Ganesh K
Nov 26 '18 at 11:27





@SavinSharma If that is possible, can you please post the code snippet or share a link where i can find this solution?

– Ganesh K
Nov 26 '18 at 11:27













I have shared a code snippet which I have used for my aws upload part.

– Savin Sharma
Nov 26 '18 at 11:53





I have shared a code snippet which I have used for my aws upload part.

– Savin Sharma
Nov 26 '18 at 11:53












1 Answer
1






active

oldest

votes


















1














You can add the aws configuration manually without using the awsconfiguration.json



build.gradle



implementation 'com.amazonaws:aws-android-sdk-core:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.6.+'


This is for ClientConfiguration part of AWS



ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setMaxErrorRetry(0);
clientConfiguration.setConnectionTimeout(3600000);
clientConfiguration.setSocketTimeout(3600000);



This is your CongnitoIdentity Part




Now get the bucketNameS3, accessKey and secretKey from some api which you can set dynamic for dynamic account.



String bucketNameS3 = "something";
String accessKey = "something";
String secretKey = "something";


Set all this value in BasicAWSCredentials object like



BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);


Next step is your AmazonS3Client object



AmazonS3Client amazonS3Client = new AmazonS3Client(basicAWSCredentials, clientConfiguration);


Here you can add the Regions to your AmazonS3Client you just have to create the object and pass it in your amazonS3Client.



Regions



Regions regions = Regions.fromName("your region name");
amazonS3Client.setRegion(Region.getRegion(regions));



Your TransferUtility Part




TransferUtilityOptions options = new TransferUtilityOptions();
options.setTransferThreadPoolSize(1);
options.setTransferServiceCheckTimeInterval(30 * 1000); // 30-second
TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.s3Client(amazonS3Client)
.transferUtilityOptions(options)
.defaultBucket(bucketNameS3)
.build();





share|improve this answer
























  • Thanks. I'll try this and let you know if it works

    – Ganesh K
    Nov 26 '18 at 12:03











  • Do you have a link from where you got this solution? If yes, please post it as well

    – Ganesh K
    Nov 26 '18 at 13:14











  • Actually i don't have the link because i did this few months back. I referred the official doc of amazon s3 at that time.

    – Savin Sharma
    Nov 26 '18 at 13:25











  • Ok. I was going through your solution and i didn't find any way to add PoolId and Region which is inside Default JsonObject of CognitoIdentity

    – Ganesh K
    Nov 26 '18 at 13:31











  • I have mentioned how you can add Region in your amazonS3Client.

    – Savin Sharma
    Nov 26 '18 at 13:55












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479093%2fdynamically-provide-awsconfiguration-while-uploading-files-using-transferutility%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You can add the aws configuration manually without using the awsconfiguration.json



build.gradle



implementation 'com.amazonaws:aws-android-sdk-core:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.6.+'


This is for ClientConfiguration part of AWS



ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setMaxErrorRetry(0);
clientConfiguration.setConnectionTimeout(3600000);
clientConfiguration.setSocketTimeout(3600000);



This is your CongnitoIdentity Part




Now get the bucketNameS3, accessKey and secretKey from some api which you can set dynamic for dynamic account.



String bucketNameS3 = "something";
String accessKey = "something";
String secretKey = "something";


Set all this value in BasicAWSCredentials object like



BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);


Next step is your AmazonS3Client object



AmazonS3Client amazonS3Client = new AmazonS3Client(basicAWSCredentials, clientConfiguration);


Here you can add the Regions to your AmazonS3Client you just have to create the object and pass it in your amazonS3Client.



Regions



Regions regions = Regions.fromName("your region name");
amazonS3Client.setRegion(Region.getRegion(regions));



Your TransferUtility Part




TransferUtilityOptions options = new TransferUtilityOptions();
options.setTransferThreadPoolSize(1);
options.setTransferServiceCheckTimeInterval(30 * 1000); // 30-second
TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.s3Client(amazonS3Client)
.transferUtilityOptions(options)
.defaultBucket(bucketNameS3)
.build();





share|improve this answer
























  • Thanks. I'll try this and let you know if it works

    – Ganesh K
    Nov 26 '18 at 12:03











  • Do you have a link from where you got this solution? If yes, please post it as well

    – Ganesh K
    Nov 26 '18 at 13:14











  • Actually i don't have the link because i did this few months back. I referred the official doc of amazon s3 at that time.

    – Savin Sharma
    Nov 26 '18 at 13:25











  • Ok. I was going through your solution and i didn't find any way to add PoolId and Region which is inside Default JsonObject of CognitoIdentity

    – Ganesh K
    Nov 26 '18 at 13:31











  • I have mentioned how you can add Region in your amazonS3Client.

    – Savin Sharma
    Nov 26 '18 at 13:55
















1














You can add the aws configuration manually without using the awsconfiguration.json



build.gradle



implementation 'com.amazonaws:aws-android-sdk-core:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.6.+'


This is for ClientConfiguration part of AWS



ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setMaxErrorRetry(0);
clientConfiguration.setConnectionTimeout(3600000);
clientConfiguration.setSocketTimeout(3600000);



This is your CongnitoIdentity Part




Now get the bucketNameS3, accessKey and secretKey from some api which you can set dynamic for dynamic account.



String bucketNameS3 = "something";
String accessKey = "something";
String secretKey = "something";


Set all this value in BasicAWSCredentials object like



BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);


Next step is your AmazonS3Client object



AmazonS3Client amazonS3Client = new AmazonS3Client(basicAWSCredentials, clientConfiguration);


Here you can add the Regions to your AmazonS3Client you just have to create the object and pass it in your amazonS3Client.



Regions



Regions regions = Regions.fromName("your region name");
amazonS3Client.setRegion(Region.getRegion(regions));



Your TransferUtility Part




TransferUtilityOptions options = new TransferUtilityOptions();
options.setTransferThreadPoolSize(1);
options.setTransferServiceCheckTimeInterval(30 * 1000); // 30-second
TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.s3Client(amazonS3Client)
.transferUtilityOptions(options)
.defaultBucket(bucketNameS3)
.build();





share|improve this answer
























  • Thanks. I'll try this and let you know if it works

    – Ganesh K
    Nov 26 '18 at 12:03











  • Do you have a link from where you got this solution? If yes, please post it as well

    – Ganesh K
    Nov 26 '18 at 13:14











  • Actually i don't have the link because i did this few months back. I referred the official doc of amazon s3 at that time.

    – Savin Sharma
    Nov 26 '18 at 13:25











  • Ok. I was going through your solution and i didn't find any way to add PoolId and Region which is inside Default JsonObject of CognitoIdentity

    – Ganesh K
    Nov 26 '18 at 13:31











  • I have mentioned how you can add Region in your amazonS3Client.

    – Savin Sharma
    Nov 26 '18 at 13:55














1












1








1







You can add the aws configuration manually without using the awsconfiguration.json



build.gradle



implementation 'com.amazonaws:aws-android-sdk-core:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.6.+'


This is for ClientConfiguration part of AWS



ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setMaxErrorRetry(0);
clientConfiguration.setConnectionTimeout(3600000);
clientConfiguration.setSocketTimeout(3600000);



This is your CongnitoIdentity Part




Now get the bucketNameS3, accessKey and secretKey from some api which you can set dynamic for dynamic account.



String bucketNameS3 = "something";
String accessKey = "something";
String secretKey = "something";


Set all this value in BasicAWSCredentials object like



BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);


Next step is your AmazonS3Client object



AmazonS3Client amazonS3Client = new AmazonS3Client(basicAWSCredentials, clientConfiguration);


Here you can add the Regions to your AmazonS3Client you just have to create the object and pass it in your amazonS3Client.



Regions



Regions regions = Regions.fromName("your region name");
amazonS3Client.setRegion(Region.getRegion(regions));



Your TransferUtility Part




TransferUtilityOptions options = new TransferUtilityOptions();
options.setTransferThreadPoolSize(1);
options.setTransferServiceCheckTimeInterval(30 * 1000); // 30-second
TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.s3Client(amazonS3Client)
.transferUtilityOptions(options)
.defaultBucket(bucketNameS3)
.build();





share|improve this answer













You can add the aws configuration manually without using the awsconfiguration.json



build.gradle



implementation 'com.amazonaws:aws-android-sdk-core:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.+'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.6.+'


This is for ClientConfiguration part of AWS



ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setMaxErrorRetry(0);
clientConfiguration.setConnectionTimeout(3600000);
clientConfiguration.setSocketTimeout(3600000);



This is your CongnitoIdentity Part




Now get the bucketNameS3, accessKey and secretKey from some api which you can set dynamic for dynamic account.



String bucketNameS3 = "something";
String accessKey = "something";
String secretKey = "something";


Set all this value in BasicAWSCredentials object like



BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials(accessKey, secretKey);


Next step is your AmazonS3Client object



AmazonS3Client amazonS3Client = new AmazonS3Client(basicAWSCredentials, clientConfiguration);


Here you can add the Regions to your AmazonS3Client you just have to create the object and pass it in your amazonS3Client.



Regions



Regions regions = Regions.fromName("your region name");
amazonS3Client.setRegion(Region.getRegion(regions));



Your TransferUtility Part




TransferUtilityOptions options = new TransferUtilityOptions();
options.setTransferThreadPoolSize(1);
options.setTransferServiceCheckTimeInterval(30 * 1000); // 30-second
TransferUtility transferUtility = TransferUtility.builder()
.context(getApplicationContext())
.s3Client(amazonS3Client)
.transferUtilityOptions(options)
.defaultBucket(bucketNameS3)
.build();






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 11:52









Savin SharmaSavin Sharma

436316




436316













  • Thanks. I'll try this and let you know if it works

    – Ganesh K
    Nov 26 '18 at 12:03











  • Do you have a link from where you got this solution? If yes, please post it as well

    – Ganesh K
    Nov 26 '18 at 13:14











  • Actually i don't have the link because i did this few months back. I referred the official doc of amazon s3 at that time.

    – Savin Sharma
    Nov 26 '18 at 13:25











  • Ok. I was going through your solution and i didn't find any way to add PoolId and Region which is inside Default JsonObject of CognitoIdentity

    – Ganesh K
    Nov 26 '18 at 13:31











  • I have mentioned how you can add Region in your amazonS3Client.

    – Savin Sharma
    Nov 26 '18 at 13:55



















  • Thanks. I'll try this and let you know if it works

    – Ganesh K
    Nov 26 '18 at 12:03











  • Do you have a link from where you got this solution? If yes, please post it as well

    – Ganesh K
    Nov 26 '18 at 13:14











  • Actually i don't have the link because i did this few months back. I referred the official doc of amazon s3 at that time.

    – Savin Sharma
    Nov 26 '18 at 13:25











  • Ok. I was going through your solution and i didn't find any way to add PoolId and Region which is inside Default JsonObject of CognitoIdentity

    – Ganesh K
    Nov 26 '18 at 13:31











  • I have mentioned how you can add Region in your amazonS3Client.

    – Savin Sharma
    Nov 26 '18 at 13:55

















Thanks. I'll try this and let you know if it works

– Ganesh K
Nov 26 '18 at 12:03





Thanks. I'll try this and let you know if it works

– Ganesh K
Nov 26 '18 at 12:03













Do you have a link from where you got this solution? If yes, please post it as well

– Ganesh K
Nov 26 '18 at 13:14





Do you have a link from where you got this solution? If yes, please post it as well

– Ganesh K
Nov 26 '18 at 13:14













Actually i don't have the link because i did this few months back. I referred the official doc of amazon s3 at that time.

– Savin Sharma
Nov 26 '18 at 13:25





Actually i don't have the link because i did this few months back. I referred the official doc of amazon s3 at that time.

– Savin Sharma
Nov 26 '18 at 13:25













Ok. I was going through your solution and i didn't find any way to add PoolId and Region which is inside Default JsonObject of CognitoIdentity

– Ganesh K
Nov 26 '18 at 13:31





Ok. I was going through your solution and i didn't find any way to add PoolId and Region which is inside Default JsonObject of CognitoIdentity

– Ganesh K
Nov 26 '18 at 13:31













I have mentioned how you can add Region in your amazonS3Client.

– Savin Sharma
Nov 26 '18 at 13:55





I have mentioned how you can add Region in your amazonS3Client.

– Savin Sharma
Nov 26 '18 at 13:55




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479093%2fdynamically-provide-awsconfiguration-while-uploading-files-using-transferutility%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Ottavio Pratesi

Tricia Helfer

15 giugno