# canvasToTempFilePath

canvasToTempFilePath(Object object) is used to export the specified area of the current canvas, generate pictures and return the file path.

## Support

This API only supports gadget calls, and the corresponding client version support is as follows.

App capability | Android | iOS | PC | Harmony | Preview
---|---|---|---|---|---
Gadget | **✓** | **✓** | **✓** | V7.35.0+ | Preview
Web app | **X** | **X** | **X** | **X** | /

## Input

This API inherits the [Standard object input](https://open.feishu.cn/document/uYjL24iN/ukzNy4SO3IjL5cjM) and has the following extended properties.

Name | Data type | Required | Default value | Description
---|---|---|---|---
canvasId | string | Yes | \- | Value of canvas-id of the canvas component to be operated.
x | number | No | 0 | X coordinate of the exported area.
y | number | No | 0 | Y coordinate of the exported area.
width | number | No | \- | Width of the exported area. The default value is the width of the Canvas element.
height | number | No | \- | Height of the exported area. The default value is the height of the Canvas element.
destWidth | number | No | \- | Width of the output image. The default value is `width` of the input parameter.
destHeight | number | No | \- | Height of the output image. The default value is `height` of the input parameter.
fileType | string | No | png | Image type. Valid values:<br>- `jpg` JPG format.<br>- `png` PNG format.
quality | number | No | 1 | Picture quality. The value range is (0, 1], the larger the value, the higher the quality. Example value: 0.3

## Output

This API inherits [Standard object output](https://open.feishu.cn/document/uYjL24iN/ukzNy4SO3IjL5cjM#8c92acb8), the extended properties of the returned `success` object are as follows.

Name | Data type | Description
---|---|---
tempFilePath | string | Temporary file path for the generated image.

##  Sample code

Example call:

```javascript
tt.canvasToTempFilePath({
  canvasId: "demo-canvas",
  x: 0,
  y: 0,
  width: 50,
  height: 50,
  destWidth: 100,
  destHeight: 100,
  success(res) {
    console.log("TempFilePath: ", res.tempFilePath);
  },
  fail(err) {
    console.log("Error", err);
  },
  complete(res) {
    console.log("CanvasToTempFilePath Complete");
  }
});
```

Sample return object:
```json
{
  "tempFilePath": "ttfile://user/xxxx"
}
```

## Error code

The `fail` return object may contain the errno attribute, indicating the error code. For detailed descriptions of errno error codes and a list of common error codes, see [Errno](https://open.feishu.cn/document/uYjL24iN/uAjMuAjMuAjM/errno).