Thumbnail Sample

Thumbnail is a sample that processes an image uploaded to OBS, resizes it to fit within a maximum dimension, and uploads the resized image back to another OBS using FunctionGraph with OBS trigger event.

Source for this sample can be found in: /samples-doc/doc-sample-obs-thumbnail.

Overview

Following diagram shows components used in this example:

Components

Deployment

This sample can be deployed using Terraform, see Prepare the Terraform environment for setup details.

Terraform deployment scripts can be found in: /samples-doc/doc-sample-obs-thumbnail/src/main/tf

Adapt file variables.tf according to your needs, see comments.

/variables.tf
# prefix will be prepended to all resource names
variable "prefix" {
  type    = string
  default = "doc-sample-obs-thumbnail"
}

# FunctionGraph: Function name
variable "function_name" {
  type    = string
  default = "createThumbnails"
}

# FunctionGraph: Handler name
variable "function_handler_name" {
  type    = string
  default = "com.opentelekomcloud.samples.Thumbnail.handleRequest"
}

# FunctionGraph: Initializer name
variable "initializer_handler_name" {
  type    = string
  default = "com.opentelekomcloud.samples.Thumbnail.initializer"
}

# Name of jar file to deploy, generated by 'mvn package' command
# and stored in folder  [project_folder]/target
variable "jar_file_name" {
  type    = string
  default = "deployment-jar-with-dependencies.jar"
}

# Resource tag:
variable "tag_app_group" {
  type = string
  default = "doc-sample-obs-thumbnail"
}

To deploy use:

terraform apply --auto-approve

References

In this sample the huaweicloud-sdk-java-obs is used to access OBS with following dependency added to the pom.xml:

  <dependency>
    <groupId>com.huaweicloud</groupId>
    <artifactId>esdk-obs-java</artifactId>
    <version>3.25.5</version>
  </dependency>

Documentation on the huaweicloud-sdk-java-obs can be found here: API Overview (SDK for Java)

Upload image file to source bucket

Linux/Ubuntu

Note

For s3cmd tool installation see: S3cmd on github.

To upload image to source bucket, following script an be used for Ubuntu users:

/samples-doc/doc-sample-obs-thumbnail/testUpload.sh
# https://github.com/opentelekomcloud/obs-s3/blob/master/s3cmd/README.md
s3cmd --access_key=${OTC_SDK_AK} --secret_key=${OTC_SDK_SK} --no-ssl \
  put ./src/test/resources/otc.jpg \
  s3://doc-sample-obs-thumbnail-createthumbnails-images/otc.jpg

Microsoft Windows

Note

For Microsoft Windows, see OBS Browser+

Alternatives (unsupported)

Huawei obsutil

Note

Huawei obsutil is available for Windows, Linux and Mac from Huawei, see: obsutil Introduction

/samples-doc/doc-sample-obs-thumbnail/testUpload.cmd
REM ########################################################################
REM Sample to upload picture to obs bucket using Huawei obsutil.
REM Huawei obsutil is available, see:
REM https://support.huaweicloud.com/intl/en-us/utiltg-obs/obs_11_0001.html
REM ########################################################################

REM for proxy use, set following environment variables
REM set HTTP_PROXY=proxy:port
REM set HTTPS_PROXY=proxy:port

obsutil.exe cp .\src\test\resources\otc.jpg ^
  obs://doc-sample-obs-thumbnail-createthumbnails-images/otc.jpg ^
  -e=https://obs.eu-de.otc.t-systems.com ^
  -i=%ACCESS_KEY% ^
  -k=%SECRET_ACCESS_KEY%