# write

## Description

Creates a new file or overrides an existing file in the cache directory of the mobile phone.

## Input / Parameter

| Name     | Description                                                                                      | Input Type | Default | Options                   | Required |
| -------- | ------------------------------------------------------------------------------------------------ | ---------- | ------- | ------------------------- | -------- |
| data     | The file data to write.                                                                          | Text       | -       | Base64, Text, Byte array  | Yes      |
| dataType | The type of file content.                                                                        | Text       | -       | Base64, Text, Byte\_Array | Yes      |
| fileName | The name of the file to write.                                                                   | Text       | -       | -                         | Yes      |
| folder   | The folder path of the file. If this input is provided, it will be appended to the storage path. | Text       | -       | -                         | No       |
| extra    | The stored value that is passed to all the callbacks.                                            | Any        | -       | -                         | No       |

## Output

| Description                        | Output Type |
| ---------------------------------- | ----------- |
| Returns the formatted information. | Object      |

### Object

| Key     | Description                                                             | Output Type |
| ------- | ----------------------------------------------------------------------- | ----------- |
| success | Boolean value to denote whether the function was executed successfully. | Text        |
| message | The message to print.                                                   | Text        |
| data    | Any additional message or data to print.                                | Text        |

## Callback

### callback

The action performed if this function runs successfully.

| Description                                           | Output Type |
| ----------------------------------------------------- | ----------- |
| Returns an object that contains the file information. | Object      |

### errorCallback

The action performed if this function does not run successfully.

| Description               | Output Type |
| ------------------------- | ----------- |
| Returns an error message. | Text        |

## Example

In this example, we will create a file with text value inside it.

### Steps

1. Drag a button component to a page in the mobile designer.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-8b2cf82f32901d530450b502f01c5eaa4657ab9d%2Fwrite-step-1.png?alt=media)
2. Select the event `press` and drag the `File.write` function to the event flow and fill in the parameter.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-998cf37475e13cafe91b7a16de7b9022383bb8a7%2Fwrite-step-2.png?alt=media)

### Result

1. Open the installed app on a device and try to press the button.
2. The file will be created and ready to use.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-00c98af9aa4374040920a8731f2991383e1ed8bd%2Fwrite-result-1.png?alt=media)
