- List containers in cloud storage (you can think about container as folder or directory in your computer and off-course you know that already).
- Create/Delete containers.
- List blobs in containers (file in directory is good equivalent of blob in container - can't be more simpler).
- Add/Delete blobs to/from containers.
Nutshell
OpenCredo Cloud Storage use Spring style 'template' concept for interacting with different cloud storage providers. There are two templates (each for different cloud storage provider):
-
AzureTemplate
AzureCredentials credentials = new AzureCredentials("YOUR_ACCOUNT_NAME", "YOUR_SECRET_KEY"); StorageOperations template = new AzureTemplate(credentials); -
S3Template
AwsCredentials credentials = new AwsCredentials("YOUR_ACCESS_KEY", "YOUR_SECRET_ACCESS_KEY"); StorageOperations template = new S3Template(credentials);
template.createContainer("container_name");
template.send("container_name", "blob-name", "blob-as-string");
List<BlobDetails> blobDetailsList = template.listContainerObjectDetails("container_name");
template.receiveAndSaveToFile(blobDetailsList.get(0).getName(), toFile);
Example with SI
Upload and download files to/from cloud storage using Spring-Integration (full example can be downloaded from here).
Files to cloud storage will be send by cloud outbound adapter:
<!-- Credentials used to connect to S3 -->
<beans:bean id="awsCredentials" class="org.opencredo.cloud.storage.s3.AwsCredentials">
<beans:constructor-arg value="${awsKey}" />
<beans:constructor-arg value="${awsSecretKey}" />
</beans:bean>
<!-- Template to access S3 cloud storage -->
<beans:bean id="template" class="org.opencredo.cloud.storage.s3.S3Template">
<beans:constructor-arg ref="awsCredentials" />
<beans:constructor-arg value="${defaultContainerName}" />
</beans:bean>
<!-- Adapter which sends file to the cloud storage -->
<cloud:outbound-channel-adapter container="${defaultContainerName}" template="template" channel="fileUploadChannel" />
Download blobs from cloud storage is done in two steps:
-
Get list of available blob details in specified container (is done by cloud inbound adapter):
<!-- Filter to accept blob once --> <beans:bean id="acceptOnceBlobNameFilter" class="org.opencredo.cloud.storage.si.filter.internal.AcceptOnceBlobNameFilter" /> <!-- Adapter which looks for blobs in cloud storage --> <cloud:inbound-channel-adapter container="${defaultContainerName}" template="template" channel="blobDetailsChannel" filter="acceptOnceBlobNameFilter"> <poller> <interval-trigger interval="5000" /> </poller> </cloud:inbound-channel-adapter> -
Download blob specified in details (is done by transformer):
<!-- Download blob specified in BlobDetails --> <service-activator input-channel="blobDetailsChannel" ref="blobDetailsTransformer" method="transform" output-channel="blobChannel" /> <!-- BlobDetails Transformer bean --> <beans:bean id="blobDetailsTransformer" class="org.opencredo.cloud.storage.si.transformer.internal.BlobToByteArrayTransformer"> <beans:constructor-arg ref="template" /> <!-- This constructor argument tells to delete blob after download --> <beans:constructor-arg value="true" /> </beans:bean>
It is important to notice that XML snippets above uses custom Spring-Integration namespace:
<beans:beans ... xmlns:cloud="http://www.opencredo.com/schema/si/cloud/storage" xsi:schemaLocation="... http://www.opencredo.com/schema/si/cloud/storage http://www.opencredo.com/schema/si/cloud/storage/opencredo-si-cloud-storage-1.0.xsd">
That's it for today.
P.S This is my first blog ever.
