# File

This class defines a File uploaded to a [[Book]].

A File can be attached to a [[Transaction]] or used to import data.

## Extends

- `ResourceProperty`\<`bkper.File`\>

### Constructor

```ts
new File(book, payload?): File;
```

#### Parameters

| Parameter | Type |
| :------ | :------ |
| `book` | [`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md) |
| `payload?` | `File` |

#### Returns

`File`

#### Overrides

```ts
ResourceProperty<bkper.File>.constructor
```

### payload

```ts
payload: File;
```

The underlying payload data for this resource

#### Inherited from

```ts
ResourceProperty.payload
```

### create()

```ts
create(): Promise;
```

Perform create new File.

#### Returns

`Promise`\<`File`\>

The created File object

***

### deleteProperty()

```ts
deleteProperty(key): this;
```

Deletes a custom property.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.deleteProperty
```

***

### getBook()

```ts
getBook(): Book;
```

Gets the Book this File belongs to.

#### Returns

[`Book`](https://bkper.com/docs/api/bkper-js/classes/book.md)

The Book instance that owns this File

***

### getContent()

```ts
getContent(): Promise<string | undefined>;
```

Gets the file content Base64 encoded.

#### Returns

`Promise`\<`string` \| `undefined`\>

The file content Base64 encoded

***

### getContentType()

```ts
getContentType(): string | undefined;
```

Gets the File content type.

#### Returns

`string` \| `undefined`

The File content type

***

### getCreatedAt()

```ts
getCreatedAt(): Date | undefined;
```

Gets the date the File was created.

#### Returns

`Date` \| `undefined`

The date the File was created

***

### getId()

```ts
getId(): string | undefined;
```

Gets the File id.

#### Returns

`string` \| `undefined`

The File id

***

### getName()

```ts
getName(): string | undefined;
```

Gets the File name.

#### Returns

`string` \| `undefined`

The File name

***

### getProperties()

```ts
getProperties(): object;
```

Gets the custom properties stored in this resource.

#### Returns

`object`

Object with key/value pair properties

#### Inherited from

```ts
ResourceProperty.getProperties
```

***

### getProperty()

```ts
getProperty(...keys): string | undefined;
```

Gets the property value for given keys. First property found will be retrieved.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| ...`keys` | `string`[] | The property keys to search for |

#### Returns

`string` \| `undefined`

The property value or undefined if not found

#### Inherited from

```ts
ResourceProperty.getProperty
```

***

### getPropertyKeys()

```ts
getPropertyKeys(): string[];
```

Gets the custom properties keys stored in this resource.

#### Returns

`string`[]

Array of property keys sorted alphabetically

#### Inherited from

```ts
ResourceProperty.getPropertyKeys
```

***

### getSize()

```ts
getSize(): number | undefined;
```

Gets the file size in bytes.

#### Returns

`number` \| `undefined`

The file size in bytes

***

### getUrl()

```ts
getUrl(): string | undefined;
```

Gets the file serving url for accessing via browser.

#### Returns

`string` \| `undefined`

The file serving url

***

### getVisibleProperties()

```ts
getVisibleProperties(): object;
```

Gets the visible custom properties stored in this resource.
Hidden properties (those ending with "_") are excluded from the result.

#### Returns

`object`

Object with key/value pair properties, excluding hidden properties

#### Inherited from

```ts
ResourceProperty.getVisibleProperties
```

***

### json()

```ts
json(): File;
```

Gets an immutable copy of the JSON payload for this resource.

#### Returns

`File`

An immutable copy of the json payload

#### Inherited from

```ts
ResourceProperty.json
```

***

### remove()

```ts
remove(): Promise;
```

Perform delete File.

#### Returns

`Promise`\<`File`\>

This File after deletion

***

### setContent()

```ts
setContent(content): File;
```

Sets the File content Base64 encoded.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `content` | `string` | The content to set (Base64 encoded) |

#### Returns

`File`

This File, for chaining

***

### setContentType()

```ts
setContentType(contentType): File;
```

Sets the File content type.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `contentType` | `string` | The content type to set |

#### Returns

`File`

This File, for chaining

***

### setName()

```ts
setName(name): File;
```

Sets the name of the File.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `name` | `string` | The name to set |

#### Returns

`File`

This File, for chaining

***

### setProperties()

```ts
setProperties(properties): this;
```

Sets the custom properties of this resource.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `properties` | \{ \[`key`: `string`\]: `string`; \} | Object with key/value pair properties |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setProperties
```

***

### setProperty()

```ts
setProperty(key, value): this;
```

Sets a custom property in this resource.

Property keys are normalized and validated by the API when saved. Keep keys
to 30 characters or fewer after normalization. Use a trailing underscore
(`_`) for hidden/internal properties.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |
| `value` | `string` \| `null` \| `undefined` | The property value, or null/undefined to clean it |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setProperty
```

***

### setVisibleProperties()

```ts
setVisibleProperties(properties): this;
```

Sets the custom properties of this resource, filtering out hidden properties.
Hidden properties are those whose keys end with an underscore "_".

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `properties` | \{ \[`key`: `string`\]: `string`; \} | Object with key/value pair properties |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setVisibleProperties
```

***

### setVisibleProperty()

```ts
setVisibleProperty(key, value): this;
```

Sets a custom property in this resource, filtering out hidden properties.
Hidden properties are those whose keys end with an underscore "_".

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `key` | `string` | The property key |
| `value` | `string` \| `null` \| `undefined` | The property value, or null/undefined to clean it |

#### Returns

`this`

This resource, for chaining

#### Inherited from

```ts
ResourceProperty.setVisibleProperty
```

***

### update()

```ts
update(): Promise;
```

Perform update File, applying pending changes.

#### Returns

`Promise`\<`File`\>

The updated File object
