The IBM® Cloud Object Storage SDK for Java how-to get a client sourcing credentials from a credentials file?
I'm trying to use The IBM® Cloud Object Storage SDK for Java and following this explanations https://console.bluemix.net/docs/services/cloud-object-storage/libraries/java.html#client-credentials where it says:
After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation
So I settled the referenced ~/.bluemix/cos_credentials in place (got it from my IBM cos instance credentials) and i expect to use this file to configure the client instead of coding the values. So now, how can a client be instantiated? Which classes of the sdk are to be used to get a working client configured to work with the bucket?
Here my cos_credentials file
"apikey": "xxxxxxxxx",
"endpoints": "https://cos-service.bluemix.net/endpoints",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxx:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::",
"iam_apikey_name": "auto-generated-apikey-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/xxxxxxxxxxxxxxxxxx::serviceid:ServiceId-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::"
ibm-cloud object-storage
add a comment |
I'm trying to use The IBM® Cloud Object Storage SDK for Java and following this explanations https://console.bluemix.net/docs/services/cloud-object-storage/libraries/java.html#client-credentials where it says:
After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation
So I settled the referenced ~/.bluemix/cos_credentials in place (got it from my IBM cos instance credentials) and i expect to use this file to configure the client instead of coding the values. So now, how can a client be instantiated? Which classes of the sdk are to be used to get a working client configured to work with the bucket?
Here my cos_credentials file
"apikey": "xxxxxxxxx",
"endpoints": "https://cos-service.bluemix.net/endpoints",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxx:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::",
"iam_apikey_name": "auto-generated-apikey-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/xxxxxxxxxxxxxxxxxx::serviceid:ServiceId-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::"
ibm-cloud object-storage
have a look at Minimal, Complete, and Verifiable example
– LuckyLikey
Nov 14 '18 at 14:58
add a comment |
I'm trying to use The IBM® Cloud Object Storage SDK for Java and following this explanations https://console.bluemix.net/docs/services/cloud-object-storage/libraries/java.html#client-credentials where it says:
After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation
So I settled the referenced ~/.bluemix/cos_credentials in place (got it from my IBM cos instance credentials) and i expect to use this file to configure the client instead of coding the values. So now, how can a client be instantiated? Which classes of the sdk are to be used to get a working client configured to work with the bucket?
Here my cos_credentials file
"apikey": "xxxxxxxxx",
"endpoints": "https://cos-service.bluemix.net/endpoints",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxx:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::",
"iam_apikey_name": "auto-generated-apikey-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/xxxxxxxxxxxxxxxxxx::serviceid:ServiceId-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::"
ibm-cloud object-storage
I'm trying to use The IBM® Cloud Object Storage SDK for Java and following this explanations https://console.bluemix.net/docs/services/cloud-object-storage/libraries/java.html#client-credentials where it says:
After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation
So I settled the referenced ~/.bluemix/cos_credentials in place (got it from my IBM cos instance credentials) and i expect to use this file to configure the client instead of coding the values. So now, how can a client be instantiated? Which classes of the sdk are to be used to get a working client configured to work with the bucket?
Here my cos_credentials file
"apikey": "xxxxxxxxx",
"endpoints": "https://cos-service.bluemix.net/endpoints",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxx:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::",
"iam_apikey_name": "auto-generated-apikey-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Writer",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/xxxxxxxxxxxxxxxxxx::serviceid:ServiceId-xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/xxxxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx::"
ibm-cloud object-storage
ibm-cloud object-storage
edited Nov 15 '18 at 17:30
drakeRxx
asked Nov 14 '18 at 13:55
drakeRxxdrakeRxx
11
11
have a look at Minimal, Complete, and Verifiable example
– LuckyLikey
Nov 14 '18 at 14:58
add a comment |
have a look at Minimal, Complete, and Verifiable example
– LuckyLikey
Nov 14 '18 at 14:58
have a look at Minimal, Complete, and Verifiable example
– LuckyLikey
Nov 14 '18 at 14:58
have a look at Minimal, Complete, and Verifiable example
– LuckyLikey
Nov 14 '18 at 14:58
add a comment |
1 Answer
1
active
oldest
votes
You should need just a few of the client classes, and none of the credential classes. Here's an example that might help get you started:
import java.sql.Timestamp;
import java.io.File;
import com.ibm.cloud.objectstorage.ClientConfiguration;
import com.ibm.cloud.objectstorage.SDKGlobalConfiguration;
import com.ibm.cloud.objectstorage.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3ClientBuilder;
import com.ibm.cloud.objectstorage.services.s3.model.ListObjectsRequest;
import com.ibm.cloud.objectstorage.services.s3.model.ObjectListing;
import com.ibm.cloud.objectstorage.services.s3.model.S3ObjectSummary;
public class CredentialsFile
private static AmazonS3 _s3Client;
/**
* @param args
*/
public static void main(String args)
SDKGlobalConfiguration.IAM_ENDPOINT = "https://iam.bluemix.net/oidc/token";
String bucketName = "<bucket-name.";
String objectKey = "<object-key";
String filePath = "/absolute/path/to/file";
String endpoint_url = "https://s3-api.us-geo.objectstorage.softlayer.net";
String location = "us";
System.out.println("Current time: " + new Timestamp(System.currentTimeMillis()).toString());
_s3Client = createClient(endpoint_url, location);
newObject(bucketName, objectKey, filePath, _s3Client);
listObjects(bucketName, _s3Client);
/**
* @param bucketName
* @param clientNum
* @param endpoint_url
* @param location
* @return AmazonS3
*/
public static AmazonS3 createClient(String endpoint_url, String location)
ClientConfiguration clientConfig = new ClientConfiguration().withRequestTimeout(5000);
clientConfig.setUseTcpKeepAlive(true);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new EndpointConfiguration(endpoint_url, location)).withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfig).build();
return s3Client;
/**
* @param bucketName
* @param keyName
* @param filePath
* @param s3Client
*/
public static void newObject(String bucketName, String keyName, String filePath, AmazonS3 s3Client)
System.out.println("Uploading new object " + keyName + " from " + filePath + "...");
s3Client.putObject(bucketName, keyName, new File(filePath));
System.out.println(keyName +" uploaded successfully.");
/**
* @param bucketName
* @param s3Client
*/
public static void listObjects(String bucketName, AmazonS3 s3Client)
System.out.println("Listing objects in bucket " + bucketName);
ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName(bucketName));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries())
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")");
System.out.println();
thanks Nick, I already managed to connect with this method, I paste what the Ibm docs says 'After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation' [link] console.bluemix.net/docs/services/cloud-object-storage/… So I'm wondering how do the SDK instantiate and auto configure a client reading from the configuraion file.
– drakeRxx
Nov 15 '18 at 17:26
The example I posted is doing that - there's no declaration of credentials anywhere, they're sourced automatically from the credentials file.
– Nick Lange
Nov 26 '18 at 15:55
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301901%2fthe-ibm-cloud-object-storage-sdk-for-java-how-to-get-a-client-sourcing-credenti%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
You should need just a few of the client classes, and none of the credential classes. Here's an example that might help get you started:
import java.sql.Timestamp;
import java.io.File;
import com.ibm.cloud.objectstorage.ClientConfiguration;
import com.ibm.cloud.objectstorage.SDKGlobalConfiguration;
import com.ibm.cloud.objectstorage.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3ClientBuilder;
import com.ibm.cloud.objectstorage.services.s3.model.ListObjectsRequest;
import com.ibm.cloud.objectstorage.services.s3.model.ObjectListing;
import com.ibm.cloud.objectstorage.services.s3.model.S3ObjectSummary;
public class CredentialsFile
private static AmazonS3 _s3Client;
/**
* @param args
*/
public static void main(String args)
SDKGlobalConfiguration.IAM_ENDPOINT = "https://iam.bluemix.net/oidc/token";
String bucketName = "<bucket-name.";
String objectKey = "<object-key";
String filePath = "/absolute/path/to/file";
String endpoint_url = "https://s3-api.us-geo.objectstorage.softlayer.net";
String location = "us";
System.out.println("Current time: " + new Timestamp(System.currentTimeMillis()).toString());
_s3Client = createClient(endpoint_url, location);
newObject(bucketName, objectKey, filePath, _s3Client);
listObjects(bucketName, _s3Client);
/**
* @param bucketName
* @param clientNum
* @param endpoint_url
* @param location
* @return AmazonS3
*/
public static AmazonS3 createClient(String endpoint_url, String location)
ClientConfiguration clientConfig = new ClientConfiguration().withRequestTimeout(5000);
clientConfig.setUseTcpKeepAlive(true);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new EndpointConfiguration(endpoint_url, location)).withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfig).build();
return s3Client;
/**
* @param bucketName
* @param keyName
* @param filePath
* @param s3Client
*/
public static void newObject(String bucketName, String keyName, String filePath, AmazonS3 s3Client)
System.out.println("Uploading new object " + keyName + " from " + filePath + "...");
s3Client.putObject(bucketName, keyName, new File(filePath));
System.out.println(keyName +" uploaded successfully.");
/**
* @param bucketName
* @param s3Client
*/
public static void listObjects(String bucketName, AmazonS3 s3Client)
System.out.println("Listing objects in bucket " + bucketName);
ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName(bucketName));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries())
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")");
System.out.println();
thanks Nick, I already managed to connect with this method, I paste what the Ibm docs says 'After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation' [link] console.bluemix.net/docs/services/cloud-object-storage/… So I'm wondering how do the SDK instantiate and auto configure a client reading from the configuraion file.
– drakeRxx
Nov 15 '18 at 17:26
The example I posted is doing that - there's no declaration of credentials anywhere, they're sourced automatically from the credentials file.
– Nick Lange
Nov 26 '18 at 15:55
add a comment |
You should need just a few of the client classes, and none of the credential classes. Here's an example that might help get you started:
import java.sql.Timestamp;
import java.io.File;
import com.ibm.cloud.objectstorage.ClientConfiguration;
import com.ibm.cloud.objectstorage.SDKGlobalConfiguration;
import com.ibm.cloud.objectstorage.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3ClientBuilder;
import com.ibm.cloud.objectstorage.services.s3.model.ListObjectsRequest;
import com.ibm.cloud.objectstorage.services.s3.model.ObjectListing;
import com.ibm.cloud.objectstorage.services.s3.model.S3ObjectSummary;
public class CredentialsFile
private static AmazonS3 _s3Client;
/**
* @param args
*/
public static void main(String args)
SDKGlobalConfiguration.IAM_ENDPOINT = "https://iam.bluemix.net/oidc/token";
String bucketName = "<bucket-name.";
String objectKey = "<object-key";
String filePath = "/absolute/path/to/file";
String endpoint_url = "https://s3-api.us-geo.objectstorage.softlayer.net";
String location = "us";
System.out.println("Current time: " + new Timestamp(System.currentTimeMillis()).toString());
_s3Client = createClient(endpoint_url, location);
newObject(bucketName, objectKey, filePath, _s3Client);
listObjects(bucketName, _s3Client);
/**
* @param bucketName
* @param clientNum
* @param endpoint_url
* @param location
* @return AmazonS3
*/
public static AmazonS3 createClient(String endpoint_url, String location)
ClientConfiguration clientConfig = new ClientConfiguration().withRequestTimeout(5000);
clientConfig.setUseTcpKeepAlive(true);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new EndpointConfiguration(endpoint_url, location)).withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfig).build();
return s3Client;
/**
* @param bucketName
* @param keyName
* @param filePath
* @param s3Client
*/
public static void newObject(String bucketName, String keyName, String filePath, AmazonS3 s3Client)
System.out.println("Uploading new object " + keyName + " from " + filePath + "...");
s3Client.putObject(bucketName, keyName, new File(filePath));
System.out.println(keyName +" uploaded successfully.");
/**
* @param bucketName
* @param s3Client
*/
public static void listObjects(String bucketName, AmazonS3 s3Client)
System.out.println("Listing objects in bucket " + bucketName);
ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName(bucketName));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries())
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")");
System.out.println();
thanks Nick, I already managed to connect with this method, I paste what the Ibm docs says 'After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation' [link] console.bluemix.net/docs/services/cloud-object-storage/… So I'm wondering how do the SDK instantiate and auto configure a client reading from the configuraion file.
– drakeRxx
Nov 15 '18 at 17:26
The example I posted is doing that - there's no declaration of credentials anywhere, they're sourced automatically from the credentials file.
– Nick Lange
Nov 26 '18 at 15:55
add a comment |
You should need just a few of the client classes, and none of the credential classes. Here's an example that might help get you started:
import java.sql.Timestamp;
import java.io.File;
import com.ibm.cloud.objectstorage.ClientConfiguration;
import com.ibm.cloud.objectstorage.SDKGlobalConfiguration;
import com.ibm.cloud.objectstorage.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3ClientBuilder;
import com.ibm.cloud.objectstorage.services.s3.model.ListObjectsRequest;
import com.ibm.cloud.objectstorage.services.s3.model.ObjectListing;
import com.ibm.cloud.objectstorage.services.s3.model.S3ObjectSummary;
public class CredentialsFile
private static AmazonS3 _s3Client;
/**
* @param args
*/
public static void main(String args)
SDKGlobalConfiguration.IAM_ENDPOINT = "https://iam.bluemix.net/oidc/token";
String bucketName = "<bucket-name.";
String objectKey = "<object-key";
String filePath = "/absolute/path/to/file";
String endpoint_url = "https://s3-api.us-geo.objectstorage.softlayer.net";
String location = "us";
System.out.println("Current time: " + new Timestamp(System.currentTimeMillis()).toString());
_s3Client = createClient(endpoint_url, location);
newObject(bucketName, objectKey, filePath, _s3Client);
listObjects(bucketName, _s3Client);
/**
* @param bucketName
* @param clientNum
* @param endpoint_url
* @param location
* @return AmazonS3
*/
public static AmazonS3 createClient(String endpoint_url, String location)
ClientConfiguration clientConfig = new ClientConfiguration().withRequestTimeout(5000);
clientConfig.setUseTcpKeepAlive(true);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new EndpointConfiguration(endpoint_url, location)).withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfig).build();
return s3Client;
/**
* @param bucketName
* @param keyName
* @param filePath
* @param s3Client
*/
public static void newObject(String bucketName, String keyName, String filePath, AmazonS3 s3Client)
System.out.println("Uploading new object " + keyName + " from " + filePath + "...");
s3Client.putObject(bucketName, keyName, new File(filePath));
System.out.println(keyName +" uploaded successfully.");
/**
* @param bucketName
* @param s3Client
*/
public static void listObjects(String bucketName, AmazonS3 s3Client)
System.out.println("Listing objects in bucket " + bucketName);
ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName(bucketName));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries())
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")");
System.out.println();
You should need just a few of the client classes, and none of the credential classes. Here's an example that might help get you started:
import java.sql.Timestamp;
import java.io.File;
import com.ibm.cloud.objectstorage.ClientConfiguration;
import com.ibm.cloud.objectstorage.SDKGlobalConfiguration;
import com.ibm.cloud.objectstorage.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3;
import com.ibm.cloud.objectstorage.services.s3.AmazonS3ClientBuilder;
import com.ibm.cloud.objectstorage.services.s3.model.ListObjectsRequest;
import com.ibm.cloud.objectstorage.services.s3.model.ObjectListing;
import com.ibm.cloud.objectstorage.services.s3.model.S3ObjectSummary;
public class CredentialsFile
private static AmazonS3 _s3Client;
/**
* @param args
*/
public static void main(String args)
SDKGlobalConfiguration.IAM_ENDPOINT = "https://iam.bluemix.net/oidc/token";
String bucketName = "<bucket-name.";
String objectKey = "<object-key";
String filePath = "/absolute/path/to/file";
String endpoint_url = "https://s3-api.us-geo.objectstorage.softlayer.net";
String location = "us";
System.out.println("Current time: " + new Timestamp(System.currentTimeMillis()).toString());
_s3Client = createClient(endpoint_url, location);
newObject(bucketName, objectKey, filePath, _s3Client);
listObjects(bucketName, _s3Client);
/**
* @param bucketName
* @param clientNum
* @param endpoint_url
* @param location
* @return AmazonS3
*/
public static AmazonS3 createClient(String endpoint_url, String location)
ClientConfiguration clientConfig = new ClientConfiguration().withRequestTimeout(5000);
clientConfig.setUseTcpKeepAlive(true);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new EndpointConfiguration(endpoint_url, location)).withPathStyleAccessEnabled(true)
.withClientConfiguration(clientConfig).build();
return s3Client;
/**
* @param bucketName
* @param keyName
* @param filePath
* @param s3Client
*/
public static void newObject(String bucketName, String keyName, String filePath, AmazonS3 s3Client)
System.out.println("Uploading new object " + keyName + " from " + filePath + "...");
s3Client.putObject(bucketName, keyName, new File(filePath));
System.out.println(keyName +" uploaded successfully.");
/**
* @param bucketName
* @param s3Client
*/
public static void listObjects(String bucketName, AmazonS3 s3Client)
System.out.println("Listing objects in bucket " + bucketName);
ObjectListing objectListing = s3Client.listObjects(new ListObjectsRequest().withBucketName(bucketName));
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries())
System.out.println(" - " + objectSummary.getKey() + " " + "(size = " + objectSummary.getSize() + ")");
System.out.println();
answered Nov 14 '18 at 17:09
Nick LangeNick Lange
51737
51737
thanks Nick, I already managed to connect with this method, I paste what the Ibm docs says 'After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation' [link] console.bluemix.net/docs/services/cloud-object-storage/… So I'm wondering how do the SDK instantiate and auto configure a client reading from the configuraion file.
– drakeRxx
Nov 15 '18 at 17:26
The example I posted is doing that - there's no declaration of credentials anywhere, they're sourced automatically from the credentials file.
– Nick Lange
Nov 26 '18 at 15:55
add a comment |
thanks Nick, I already managed to connect with this method, I paste what the Ibm docs says 'After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation' [link] console.bluemix.net/docs/services/cloud-object-storage/… So I'm wondering how do the SDK instantiate and auto configure a client reading from the configuraion file.
– drakeRxx
Nov 15 '18 at 17:26
The example I posted is doing that - there's no declaration of credentials anywhere, they're sourced automatically from the credentials file.
– Nick Lange
Nov 26 '18 at 15:55
thanks Nick, I already managed to connect with this method, I paste what the Ibm docs says 'After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation' [link] console.bluemix.net/docs/services/cloud-object-storage/… So I'm wondering how do the SDK instantiate and auto configure a client reading from the configuraion file.
– drakeRxx
Nov 15 '18 at 17:26
thanks Nick, I already managed to connect with this method, I paste what the Ibm docs says 'After generating a Service Credential, the resulting JSON document can be saved to ~/.bluemix/cos_credentials. The SDK will automatically source credentials from this file unless other credentials are explicitly set during client creation' [link] console.bluemix.net/docs/services/cloud-object-storage/… So I'm wondering how do the SDK instantiate and auto configure a client reading from the configuraion file.
– drakeRxx
Nov 15 '18 at 17:26
The example I posted is doing that - there's no declaration of credentials anywhere, they're sourced automatically from the credentials file.
– Nick Lange
Nov 26 '18 at 15:55
The example I posted is doing that - there's no declaration of credentials anywhere, they're sourced automatically from the credentials file.
– Nick Lange
Nov 26 '18 at 15:55
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301901%2fthe-ibm-cloud-object-storage-sdk-for-java-how-to-get-a-client-sourcing-credenti%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
have a look at Minimal, Complete, and Verifiable example
– LuckyLikey
Nov 14 '18 at 14:58