Use the style command to create, retrieve, delete, and list image styles on an OSS bucket.
An image style is a named preset that stores an Image Processing parameter string. Once defined, apply it to any object URL instead of repeating the full parameter string each time.
Prerequisites
Before you begin, make sure you have:
ossutil 1.7.16 or later (the
stylecommand is not available in earlier versions)The required RAM permissions for the operations you plan to run: For details on granting these permissions, see Attach a custom policy to a RAM user.
Operation Required permission Create an image style oss:PutStyleRetrieve an image style oss:GetStyleDelete an image style oss:DeleteStyle
ossutil 1.6.16 and later let you invoke the tool as ossutil on any operating system. Earlier versions require the binary name to match the operating system. For details, see ossutil command reference.Create an image style
Synopsis
ossutil style --method put oss://<bucketname>/ <stylename> <local_xml_file>Parameters
| Parameter | Required | Description |
|---|---|---|
bucketname | Yes | Name of the bucket |
stylename | Yes | Name to assign to the image style |
local_xml_file | Yes | Path to the local XML file that defines the style content (for example, config.xml) |
The XML file must follow this structure:
<?xml version="1.0" encoding="UTF-8"?>
<Style>
<Content>image/resize,p_50</Content>
</Style>The <Content> element holds an Image Processing parameter string. For the full list of supported operations and values, see Image Processing parameters.
Example
Create config.xml with the following content:
<?xml version="1.0" encoding="UTF-8"?>
<Style>
<Content>image/resize,p_50</Content>
</Style>Then run:
ossutil style --method put oss://examplebucket/ examplestyle config.xmlThe following output confirms the style was created:
0.299514(s) elapsedRetrieve an image style
Synopsis
ossutil style --method get oss://<bucketname>/ <stylename> [local_xml_file]Parameters
| Parameter | Required | Description |
|---|---|---|
bucketname | Yes | Name of the bucket |
stylename | Yes | Name of the image style to retrieve |
local_xml_file | No | Path to a local file where the result is saved. If omitted, the result prints to stdout. |
Examples
Print the style definition to stdout:
ossutil style --method get oss://examplebucket/ examplestyleOutput:
<?xml version="1.0" encoding="UTF-8"?>
<Style>
<Name>examplestyle</Name>
<Content>image/resize,p_100</Content>
<CreateTime>Thu, 22 Dec 2022 13:59:06 GMT</CreateTime>
<LastModifyTime>Thu, 22 Dec 2022 13:59:06 GMT</LastModifyTime>
</Style>
0.150473(s) elapsedSave the style definition to a local file:
ossutil style --method get oss://examplebucket/ examplestyle local.xmlThe following output confirms the file was saved:
0.214483(s) elapsedlocal.xml contains:
<?xml version="1.0" encoding="UTF-8"?>
<Style>
<Name>examplestyle</Name>
<Content>image/resize,p_100</Content>
<CreateTime>Thu, 22 Dec 2022 13:59:06 GMT</CreateTime>
<LastModifyTime>Thu, 22 Dec 2022 13:59:06 GMT</LastModifyTime>
</Style>Delete an image style
Synopsis
ossutil style --method delete oss://<bucketname>/ <stylename>Parameters
| Parameter | Required | Description |
|---|---|---|
bucketname | Yes | Name of the bucket |
stylename | Yes | Name of the image style to delete |
Example
ossutil style --method delete oss://examplebucket examplestyleThe following output confirms the style was deleted:
0.184183(s) elapsedList image styles
Synopsis
ossutil style --method list oss://<bucketname>/ [local_xml_file]Parameters
| Parameter | Required | Description |
|---|---|---|
bucketname | Yes | Name of the bucket |
local_xml_file | No | Path to a local file where the results are saved. If omitted, results print to stdout. |
Examples
Print all styles to stdout:
ossutil style --method list oss://examplebucket/Output:
<?xml version="1.0" encoding="UTF-8"?>
<StyleList>
<Style>
<Name>examplestyle1</Name>
<Content>image/resize,p_100</Content>
<CreateTime>Thu, 22 Dec 2022 13:59:06 GMT</CreateTime>
<LastModifyTime>Thu, 22 Dec 2022 13:59:06 GMT</LastModifyTime>
</Style>
<Style>
<Name>examplestyle2</Name>
<Content>image/resize,p_100</Content>
<CreateTime>Thu, 22 Dec 2022 13:59:06 GMT</CreateTime>
<LastModifyTime>Thu, 22 Dec 2022 13:59:06 GMT</LastModifyTime>
</Style>
</StyleList>
0.155333(s) elapsedSave all styles to a local file:
ossutil style --method list oss://examplebucket/ local.xmlThe following output confirms the file was saved:
2.655387(s) elapsedlocal.xml contains:
<?xml version="1.0" encoding="UTF-8"?>
<StyleList>
<Style>
<Name>examplestyle1</Name>
<Content>image/resize,p_100</Content>
<CreateTime>Thu, 22 Dec 2022 13:59:06 GMT</CreateTime>
<LastModifyTime>Thu, 22 Dec 2022 13:59:06 GMT</LastModifyTime>
</Style>
<Style>
<Name>examplestyle2</Name>
<Content>image/resize,p_100</Content>
<CreateTime>Thu, 22 Dec 2022 13:59:06 GMT</CreateTime>
<LastModifyTime>Thu, 22 Dec 2022 13:59:06 GMT</LastModifyTime>
</Style>
</StyleList>