Docs > API > Asset
An Asset is a binary or text file.
Asset inherits from Item.
Asset inherits from Item.
You can construct a new binary asset by specifying the content using base-64 encoding.
| Properties | |
|---|---|
| attributes | Provides read/write access to the asset's attributes. For example:var alt = asset.attributes["alt"]; |
| data | The asset's data. This is a write-only property: you can't retrieve an asset's content using this property but you can use it to set an asset's content. Binary data should be serialized as a base64-encoded string. |
| mimeType | The asset's MIME type. For example: "text/css" |
| Methods | |
|---|---|
| isImage() | Returns true if the asset is an image. |
| resize({ width: x, height: y, [path: newPath,] [replace: true|false,] [transform: "crop" | "constrain" | "stretch",] }) | Resize an image asset. An asset can be resized in-situ by omitting a "path" property and specifying replace: true. Otherwise, it is resized to the location specified by "path". In the case where x:y is a different ratio to the original width:height, a further transformation needs to be made in order make the image fit the new dimensions. This must be one of the following: "constrain": This is the default value, and it means: Treat the new dimensions as a maximum height and maximum width. The resized image might end up with width<x or height<y (but not both!) i.e. expand/contract the original image until it reaches the maximum size that would fit into an x by y constraining box. "crop": Crop the image such that it is in the same proportions as x,y, and then expand/contract to the desired size. Cropping takes place symmetrically. "stretch": The original image is stretched/squashed to meet the new dimensions. The resulting image may look "out of proportion". |
| save() | Save changes back to the content repository. |



