Store an image of Adempiere Application in Amazon S3 (Simple Storage Service)


Problem Statement

ADempiere has very good mechanism to upload, store and view images. Also, image  management is integrated smoothly with the standard ADempiere windows, which provides seamless management of images on the web platform. All the images are stored in database and on need basis images are retrieved from the database to show them on the web application. Even though it appears good, it has following limitations

  • Image rendering will be slower as it has to load from application database
  • As number of images and size of image increases, the database will have performance issues

Amazon S3 provides a scalable option for storing of images or static content and rendering of images on screen will also be faster with Amazon Cloud Front.

Scope of this article

This article talks about integration of Amazon S3 and ADempiere to ensure that adding documents and images has very less impact on the application server.

Technology

  • AmazonS3 API
  • Adempiere 3.6.0 or above

Prerequisites

Following jars required

  • aws-java-sdk-1.3.24.jar
  • httpclient-4.1.1.jar
  • httpcore-4.1.jar

Details

Step 1: Changes in ADempiere

We need to make changes in ADempiere to connect to remote storage system that is Amazon’s Simple Storage Service (S3), and use its API to store Adempiere’s Image into Amazon’s storage location. We will use AmazonS3 API (AWS SDK for Java) to achieve this.

  1. Add required jars into your project build path. JarFiles
  2. Create system configurator variable, which will act as a switch for Storage functionality. Based on this system configuration parameter, system will decide either to use standard storage or amazon stroage
  3. Create AWSEnv.properties file, which holds secret key and access key. We can enhance standard Adempiere.properties file to hold this new variables. But that will lead to more code changes.
  4. Prepare a new util class which will have generic methods to connect to Amazon S3  (AmazonS3Client()), to create buckets (createBucket()), to store files  (putObject()) and to retrieve files  (generatePresignedUrl()). Consider following items while preparing generic methods
    1. Once image is stored in Amazon S3 (putObject()), it returns unique URL for this image (generatePresignedUrl()), store this URL in image object of Adempiere to render on web browserAttachmentandImageURL
    2. Any entity stored in Amazon S3 will have definite life period, you may like to mention that as per the project need
    3. You can create your own folder structure in Amazon S3, to identify files uniquely
  5. Make code changes in Image Model class to invoke generic methods defined in previous step

After making all the above mentioned changes,  ADempiere is ready to store/render images  to/from Amazon S3 respectively

Note:

To use AmazonS3 you need to sign up for an Amazon account. It provides you Access Key & Secret Key.  

Step 2: Let us see how it works in ADempiere

Let us store one Image file into Amazon’s secured storage location and see how it renders into web browser

  1. Login into  ADempiere with GardenAdmin role AdempiereLogin
  2. Open business partner window and click on ‘Logo’ widget to upload business partner’s image

    Business Partner

    Business Partner

  3. Click on the select file and browse for the desired imageSelect File Image from desktop
  4. Click on upload and save the file on Amazon and log into AWS management console and verify whether image is uploaded or not S3 Management Console
  5. Now in business partner window, you can see the uploaded image being rendered in ‘Logo’ widget LogoImage

Summary

With the minor changes, the image management in ADempiere becomes more effective and efficient. The end user experience while viewing contents consisting of images or static content on web improves significantly.

Walking Tree promotes ADempiere and we support the users as well as the developers to ensure that the business is able to take complete advantage of ADempiere’s wonderful capability. In case you are looking for a professional assistance then do visit our website to get in touch with us.

Reference

  1. http://docs.aws.amazon.com/AmazonS3/latest/dev/Welcome.html
  2. http://docs.aws.amazon.com/AmazonS3/latest/API/
  3. http://www.adempiere.com/ManPageW_SystemImage
Tagged with: , , ,
Posted in ADempiere

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

We Have Moved Our Blog!

We have moved our blog to our company site. Check out https://walkingtree.tech/index.php/blog for all latest blogs.

Sencha Select Partner Sencha Training Partner
Xamarin Authorized Partner
Recent Publication
%d bloggers like this: