PhotoSharing Part I: Setting up the Photo Sharing Android Application-阿里云开发者社区

开发者社区> 芷沁> 正文

PhotoSharing Part I: Setting up the Photo Sharing Android Application

简介: We will build a photo sharing Android app with real-time image uploading and downloading functionality using Alibaba Cloud OSS.


By Sai Sarath Chandra, Alibaba Cloud Tech Share Author and Alibaba Cloud MVP

We are going to build a photo sharing Android application with real-time image uploading and downloading capabilities using Alibaba Cloud Object Storage Service (OSS). We will also use the additional capabilities of OSS like image processing like image rotate, resize, crop, and watermark.

This tutorial is fairly involved and is divided into 3 parts.

1 Setting up the photo sharing Android application
2 Understanding the real-time upload and download features of the Alibaba OSS.
3 Understanding the image processing capabilities and bootstrapping the whole application.

Unlike my previous tutorials, I will share some design perspective of the application in this tutorial. I will explain how I come about designing the application. Please raise a pull requests/issues in my GitHub repository if you have any ideas or feedback.

Let's start by setting up the environment for the application.

In my previous tutorials I used the Actual AccessKey ID, Access Key Secret for accessing any service. Here I want to demonstrate this application using the Security Token Service (STS) server.

Setting & Accessing the Security Token Service (STS) Server

Keep in mind I still use the STS Server to create the user with all the administrator rights for the simplicity of the application.

1.Open the following link for downloading the STS Java SDK for AlibabaCloud. At the time of this writing the "Java SDK (2015-08-25) Version 2.1.6" is the latest version. It might happen the versions change but almost the code remains the same.
2.Unzip the downloaded file. You will find some contents like the below image


3.I used Eclipse to run the code. In your Eclipse, navigate to File > Import > Existing Maven Project.


4.After selecting the following option, you will see the immediate dialog asking for the directory of your code repo downloaded. Eclipse should automatically detect the code and show the pom.xml file. Select the checkbox and select finish.


5.After importing the code, you can see the below project structure.


6.Open "", this is where you need to make changes to get your STS related values.
7.There are three values we need to change in order to get new values.

d.region ID

8.Navigate to console to get the values.

Setting Up user and Accessing the Key values:

1.Login to Alibaba Cloud and Navigate to your console and check for "Resource access management"


2.If you are opening the resource access management for the first time you need to activate the service by clicking the "Activate Now" button. 2.


Creating User in RAM

1.Once the service is activated, you can see "Create User" to create the resource in your resource access management. Click to proceed.


2.Fill the corresponding "User Name", "Display Name" and "Description" as required. Here the "User name" is mandatory and the "Display Name" and the "Description" are optional. Make sure you check the checkbox to generate an access key for the corresponding user.


3.When the access key is created, you will see a prompt stating "Access key successfully created". Additionally, you can save the access key information with a click of a button. You are strongly recommended to do this as it is a one-time activity – you will not be able to download the access key later.


4.Once the access key is created name and the display name which you have provided along with the description on the dashboard. Click on "Manage" to see other details.


5.There are two more options other than "User Details", which are "User Authorization policies" and "User group". Click on "User Authorization policies" and verify if you have any other User related Authorization policies available.



6.Navigate to the "Resource Access Management" dashboard where you can see different options like Users, Groups, Policies, Roles and Settings. Click on Roles > Create new role.


Creating a Role

You can create a new role in 4 steps

1.Step 1: Select user role as we are assigning this role to a particular user


2.Step 2: Select "Current Alibaba cloud account" and leave the "Trusted Alibaba cloud account ID to the default value and click next. I have blurred my Alibaba Cloud ID for security purposes.


3.Step 3: You can create your own role name. I am giving the name of "Admin" as this particular role will have all the access privileges of the administrator. You can even provide description if required. Click on create once complete.


4.Step 4: Once the rule is created you will see the below prompt. Click on "Authorize".


5.After clicking "Authorize", select administrator access from "Available Authorisation Policy Names" and click on the right Arrow (>). If everything is correctly configured, you should see something similar to the image below.


6.Navigate to dashboard click on Roles, and you can see the new role name added. In my case, it is "Admin". Click on manage to see the role details, where you will find arn. Take note of this value as we will be using it to generate the STS Token.



7.Record the access key ID and the access key secret from the csv file downloaded at the initial step while creating the user.

8.Now, for generating the STS token, replace Accesskey ID, Accesskey secret and Role ARN in the following variables of the StsServiceSample.Java

String accessKeyId = "Replace your Details Here";
String accessKeySecret = "Replace your Details Here";
String roleArn = "Replace your Details Here";

9.Right click on the Java file and choose "Run As" select Java application. You should see the output in the Console with all three values access key ID access key secret, and the STS token should be generated.

10.Finally, make sure you save your region information as we need to replace the region information in the JAVA file later either by replacing the variable or updating the variable.

public static final String REGION_CN_HANGZHOU = "cn-hangzhou";

IClientProfile profile = DefaultProfile.getProfile(REGION_CN_HANGZHOU, accessKeyId, accessKeySecret);

Activating and Setting up OSS:

1.Navigate to Object Storage Service in the console. You may be required to activate the OSS service if you are opening it for the first time as we did it for the Resource Access Management service. Make sure the region you selected have the image processing capabilities.

2.Once the service is activated, click on Create Bucket to create a storage bucket for our application.


3.You can fill in the relevant information in the corresponding form. You can use the Standard Storage as the storage class because files inside the application will be frequently accessed by multiple parties. The ACL level can be just Public Read/Write for the sake of simplicity of the application. Make sure you keep a reference of the endpoint as you need to update it in the property files.



In this section of setting up the photo sharing application we saw how to create Security Token Service (STS) credentials using Resource Access Management (RAM). We can actually create a new user and assign multiple access permissions using RAM. In production scenarios, we typically want to use RAM to create users dynamically or create user groups that only have certain level of access to the application. We can even create multiple users to access our app with limited access levels. Once the user is created, you can see it in the dashboard. A separate link will be created to signing into the console for RAM users.

You can typically move the STS code into the application. Whenever the credentials expire, you can make the application call STS to generate new credentials. You can even make an HTTP call to the STS to fetch credentials, but I recommend to integrate the Java code because it is lot easier than making in HTTP/HTTPS call.

In following section, I will be discussing the basic synchronous and asynchronous functionalities of OSS & and image processing capabilities in Android.


阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
4479 0
windows server 2008阿里云ECS服务器安全设置
最近我们Sinesafe安全公司在为客户使用阿里云ecs服务器做安全的过程中,发现服务器基础安全性都没有做。为了为站长们提供更加有效的安全基础解决方案,我们Sinesafe将对阿里云服务器win2008 系统进行基础安全部署实战过程! 比较重要的几部分 1.
5457 0
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
5728 0
443 0
腾讯云服务器 设置ngxin + fastdfs +tomcat 开机自启动
在tomcat中新建一个可以启动的 .sh 脚本文件 /usr/local/tomcat7/bin/ export JAVA_HOME=/usr/local/java/jdk7 export PATH=$JAVA_HOME/bin/:$PATH export CLASSPATH=.
2140 0
阿里云安全组设置详细图文教程(收藏起来) 阿里云服务器安全组设置规则分享,阿里云服务器安全组如何放行端口设置教程。阿里云会要求客户设置安全组,如果不设置,阿里云会指定默认的安全组。那么,这个安全组是什么呢?顾名思义,就是为了服务器安全设置的。安全组其实就是一个虚拟的防火墙,可以让用户从端口、IP的维度来筛选对应服务器的访问者,从而形成一个云上的安全域。
3829 0