# WsContents

## Overview

The `WsContents` class represents the contents or parts of an HTTP request. It provides functionality to access metadata and content details of uploaded files or form data in a request. The contents include attributes such as the content name, field name, content type, size, and raw byte data. Additionally, it allows retrieval of the content as a string with a specified encoding.

Key methods include `getName()` to get the content name, `getFieldName()` to retrieve the field name, `getContentType()` to access the MIME type, and `getSize()` to get the content size in bytes. The class also provides methods like `getBytes()` to obtain raw byte data and `getString(encoding)` to convert the content into a string using a specified encoding.

## Properties Summarized

| Type                                                     | Name                        | Summary                    |
| -------------------------------------------------------- | --------------------------- | -------------------------- |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)   | [bytes](#bytes)             | Get contents bytes.        |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [contentType](#contenttype) | Get contents content type. |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [fieldName](#fieldname)     | Get contents field name.   |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [name](#name)               | Get contents name.         |
| [Number](/reference/servoycore/dev-api/js-lib/number.md) | [size](#size)               | Get contents size.         |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [string](#string)           | Get contents as string.    |

## Properties Detailed

### bytes

Get contents bytes.

**Type**\
[Array](/reference/servoycore/dev-api/js-lib/array.md)

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
   var bytes = contents[0].getBytes();
}
```

### contentType

Get contents content type.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
   var contentType = contents[0].getContentType();
}
```

### fieldName

Get contents field name.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
   var fieldName = contents[0].getFieldName();
}
```

### name

Get contents name.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
   var name = contents[0].getName();
}
```

### size

Get contents size.

**Type**\
[Number](/reference/servoycore/dev-api/js-lib/number.md)

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
   var size = contents[0].getSize();
}
```

### string

Get contents as string.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var request = plugins.rest_ws.getRequest();
var contents = request.getContents();
if (contents.length > 0) {
   var string = contents[0].getString('UTF-8');
}
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoyextensions/server-plugins/rest_ws/wscontents.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
