Help Center> Object Storage Service> Image Processing> FAQ> How Do I Access Image Processing with a URL?
Updated on 2024-03-04 GMT+08:00

How Do I Access Image Processing with a URL?

Accessing Images Not Publicly Readable

To access images that cannot be read by the public, add image processing parameters during signature calculation to create a signed temporary URL.

A Java SDK sample code is provided as follows. For details, see SDK Overview.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Here uses the endpoint corresponding to the CN-Hong Kong region as an example.
String endPoint = "https://obs.ap-southeast-1.myhuaweicloud.com"; 
// Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables.
// In this example, the AK and SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY.
// Obtain an AK and SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
String ak = System.getenv("ACCESS_KEY_ID");
String sk = System.getenv("SECRET_ACCESS_KEY");
 
// Create an ObsClient instance.
ObsClient obsClient = new ObsClient(ak, sk, endPoint); 

// Set the URL validity period to 3600 seconds.
long expireSeconds = 3600L;   
TemporarySignatureRequest request = new TemporarySignatureRequest(HttpMethodEnum.GET, expireSeconds); request.setBucketName("bucketname"); 
request.setObjectKey("objectname");  

// Configure image processing parameters.
Map<String,Object> queryParams = new HashMap<String, Object>(); 
queryParams.put("x-image-process", "image/resize,m_fixed,w_100,h_100/rotate,100"); request.setQueryParams(queryParams);  

// Obtain the URL that supports image processing.
TemporarySignatureResponse response = obsClient.createTemporarySignature(request);
System.out.println("Getting object using temporary signature url:"); 
System.out.println("\t" + response.getSignedUrl()); 

Accessing Images Publicly Readable

To access images that can be read by the public, add image processing parameters to the URL request.

Sample URL for obtaining the information about the example.jpg image:

https://hw-image-demo.obs.ap-southeast-1.myhuaweicloud.com/example.jpg?x-image-process=image/info