Use the info action to retrieve metadata from an image stored in OSS. Depending on the image, the response includes basic image properties or both basic properties and Exchangeable Image File Format (EXIF) data — camera settings, GPS coordinates, and other shooting attributes.
Limitations
Supported formats: JPG, PNG, BMP, GIF, WebP, TIFF, and HEIC.
PNG images return only basic properties. EXIF data is not available for PNG images.
The
infoaction cannot be combined with other image processing actions in a single request. For example,image/resize,s_700,limit_0/infois invalid.
Parameters
| Parameter | Value | Return format |
|---|---|---|
| Action | info | JSON |
The process string to use in requests is image/info.
Query image information
Query information about a public image
Append ?x-oss-process=image/info to the public URL of an image.
Image without EXIF data
https://image-demo.oss-cn-hangzhou.aliyuncs.com/example.jpg?x-oss-process=image/infoFor images without EXIF data, the response contains basic image properties only:
{
"FileSize": {"value": "21839"},
"Format": {"value": "jpg"},
"FrameCount": {"value": "1"},
"ImageHeight": {"value": "267"},
"ImageWidth": {"value": "400"},
"ResolutionUnit": {"value": "1"},
"XResolution": {"value": "1/1"},
"YResolution": {"value": "1/1"}
}Image with EXIF data
https://image-demo.oss-cn-hangzhou.aliyuncs.com/f.jpg?x-oss-process=image/infoFor images with EXIF data, the response includes both basic properties and EXIF fields. For a full list of EXIF field definitions, see Exif Version 2.31.
{
"Compression": {"value": "6"},
"DateTime": {"value": "2015:02:11 15:38:27"},
"ExifTag": {"value": "2212"},
"FileSize": {"value": "23471"},
"Format": {"value": "jpg"},
"GPSLatitude": {"value": "0deg "},
"GPSLatitudeRef": {"value": "North"},
"GPSLongitude": {"value": "0deg "},
"GPSLongitudeRef": {"value": "East"},
"GPSMapDatum": {"value": "WGS-84"},
"GPSTag": {"value": "4292"},
"GPSVersionID": {"value": "2 2 0 0"},
"ImageHeight": {"value": "333"},
"ImageWidth": {"value": "424"},
"JPEGInterchangeFormat": {"value": "4518"},
"JPEGInterchangeFormatLength": {"value": "3232"},
"Orientation": {"value": "7"},
"ResolutionUnit": {"value": "2"},
"Software": {"value": "Microsoft Windows Photo Viewer 6.1.7600.16385"},
"XResolution": {"value": "96/1"},
"YResolution": {"value": "96/1"}
}Each field is returned as{"value": "<field-value>"}. To read a field in your code, access the nestedvaluekey — for example,response["Format"]["value"].
Query information about a private image
For private images, use an OSS SDK to call GetObject with the image/info process parameter, or generate a signed URL and open it in a browser or HTTP client.
The following examples use OSS SDKs to query information about a private image. For other SDK languages, see SDK reference.
For information about implementation modes, see IMG implementation modes.
Java
Java SDK 3.17.4 or later is required.
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.GetObjectRequest;
import com.aliyuncs.exceptions.ClientException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class Demo {
public static void main(String[] args) throws ClientException {
// Specify the endpoint of the region where the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the region ID. Example: cn-hangzhou.
String region = "cn-hangzhou";
// Read access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
EnvironmentVariableCredentialsProvider credentialsProvider =
CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name.
String bucketName = "examplebucket";
// Specify the image name. For images in a directory, use the full path: exampledir/example.jpg.
String key = "example.jpg";
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key);
getObjectRequest.setProcess("image/info");
OSSObject ossObject = ossClient.getObject(getObjectRequest);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = ossObject.getObjectContent().read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
System.out.println(baos.toString("UTF-8"));
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
} finally {
ossClient.shutdown();
}
}
}PHP
PHP SDK 2.7.0 or later is required.
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
try {
// Read access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
$provider = new EnvironmentVariableCredentialsProvider();
// Specify the endpoint of the region where the bucket is located.
$endpoint = 'https://oss-cn-hangzhou.aliyuncs.com';
// Specify the bucket name.
$bucket = 'examplebucket';
// Specify the image name. For images in a directory, use the full path: exampledir/example.jpg.
$key = 'example.jpg';
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
$options[$ossClient::OSS_PROCESS] = "image/info";
$result = $ossClient->getObject($bucket, $key, $options);
var_dump($result);
} catch (OssException $e) {
printf($e->getMessage() . "\n");
}Go
Go SDK 3.0.2 or later is required.
package main
import (
"fmt"
"io"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Read access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the endpoint and region where the bucket is located.
client, err := oss.New(
"https://oss-cn-hangzhou.aliyuncs.com", "", "",
oss.SetCredentialsProvider(&provider),
oss.AuthVersion(oss.AuthV4),
oss.Region("cn-hangzhou"),
)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
bucket, err := client.Bucket("examplebucket")
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the image name. For images in a directory, use the full path: exampledir/example.jpg.
body, err := bucket.GetObject("example.jpg", oss.Process("image/info"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
defer body.Close()
data, err := io.ReadAll(body)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
fmt.Println(string(data))
}RESTful API
To call the OSS API directly, include a V4 signature in your request. For details, see Signature version 4 (recommended).
Add the x-oss-process parameter to a GetObject request:
GET /oss.jpg?x-oss-process=image/info HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218eFAQ
How do I query information about a private image using a signed URL?
Generate a signed URL with the image/info process parameter, then open the URL in a browser.
The following example uses OSS SDK for Java to generate a signed URL that expires in 10 minutes:
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.GeneratePresignedUrlRequest;
import java.net.URL;
import java.util.Date;
public class Demo {
public static void main(String[] args) throws Throwable {
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
String region = "cn-hangzhou";
// Read access credentials from environment variables.
// Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
EnvironmentVariableCredentialsProvider credentialsProvider =
CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
// Specify the full path of the image object. Do not include the bucket name.
String objectName = "exampleobject.jpg";
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
String style = "image/info";
// Set the signed URL to expire in 10 minutes.
Date expiration = new Date(new Date().getTime() + 1000 * 60 * 10);
GeneratePresignedUrlRequest req =
new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.GET);
req.setExpiration(expiration);
req.setProcess(style);
URL signedUrl = ossClient.generatePresignedUrl(req);
System.out.println(signedUrl);
} catch (OSSException oe) {
System.out.println("Error message: " + oe.getErrorMessage());
System.out.println("Error code: " + oe.getErrorCode());
System.out.println("Request ID: " + oe.getRequestId());
System.out.println("Host ID: " + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error message: " + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}Open the signed URL in a browser to retrieve the image information.