# Manage Stream Files

You can use the Wowza Streaming Engine™ media server software REST API to identify, add, and manage stream files in a Wowza Streaming Engine instance.

A stream file is an alias for a complex, URI-based stream name from a source such as an MPEG-TS encoder or IP camera. For example, a stream from an MPEG-TS encoder might have a name like `udp://0.0.0.0:10000`. You can replace that with a stream file such as `mycoolevent.stream`. Players can then use `mycoolevent.stream` in playback URLs in place of the URI-based stream name. Stream files are stored in the `/Library/WowzaStreamingEngine/content` directory and have a `.stream` file extension.

> **Notes:**  
> - Wowza Streaming Engine 4.3.0 or later is required.  
> - PHP examples for the tasks in this article are available in the **tests** folder of the [PHP REST Library for Wowza Streaming Engine on GitHub](https://github.com/WowzaMediaSystems/wse-rest-library-php).

## Get a List of Stream Files

View a list of stream files associated with an application:

**Example request**

```bash
curl -X GET \
  -H "Accept:application/json; charset=utf-8" \
  -H "Content-Type:application/json; charset=utf-8" \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/streamfiles
```

View a list of stream files associated with an application named _testlive_:

**Example request**

```bash
curl -X GET \
  -H "Accept:application/json; charset=utf-8" \
  -H "Content-Type:application/json; charset=utf-8" \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/testlive/streamfiles
```

The command should return a response similar to the following:

**Example response**

```json
{
  "serverName": "serverName",
  "streamFiles": [
    {
      "id": "metallica",
      "href": "http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/testlive/streamfiles/streamfile1"
    },
    {
      "id": "saosin",
      "href": "http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/testlive/streamfiles/streamfile2"
    }
  ]
}
```

View the details of a stream file:

**Example request**

```bash
curl -X GET \
  -H 'Accept:application/json; charset=utf-8' \
  -H 'Content-type:application/json; charset=utf-8' \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/streamfiles/{streamfileName}
```

The command should return a response that shows the stream file's name and the source URI, like this:

**Example response**

```json
{
  "version": "1430317484000",
  "serverName": "serverName",
  "uri": "udp://0.0.0.0:10000",
  "name": "streamfileName"
}
```

## Add a Stream File

Add a stream file named _creedence_:

**Example request**

```bash
curl -X POST \
  -H 'Accept:application/json; charset=utf-8' \
  -H 'Content-Type:application/json; charset=utf-8' \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/streamfiles \
  -d '{
    "name": "creedence",
    "serverName": "serverName",
    "uri": "udp://1.2.3.4:10000"
  }'
```

Depending on the stream type, change the protocol for the value in the `uri` string. The command returns a response similar to this:

**Example response**

```json
{
  "success": true,
  "message": "",
  "data": null
}
```

## Update a Stream File

When using the REST API, you can customize the advanced properties of a stream file. The following example changes the URI to an Axis IP camera and reduces the stream timeout and reconnect wait time for the stream file named _creedence_:

**Example request**

```bash
curl -X PUT \
  -H 'Accept: application/json; charset=utf-8' \
  -H 'Content-Type: application/json; charset=utf-8' \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/streamfiles/creedence/adv \
  -d '{
    "sourceControlDriver": "",
    "advancedSettings": [{
      "sectionName": "Common",
      "canRemove": false,
      "defaultValue": "null",
      "documented": false,
      "name": "uri",
      "section": "null",
      "type": "string",
      "value": "rtsp://user:pass@[ip-camera]:554/axis-media/media.amp?videocodec=h264&streamprofile=400",
      "enabled": true
    }, {
      "sectionName": "Common",
      "canRemove": true,
      "defaultValue": "12000",
      "documented": true,
      "name": "streamTimeout",
      "section": "null",
      "type": "integer",
      "value": "0",
      "enabled": true
    }, {
      "sectionName": "Common",
      "canRemove": false,
      "defaultValue": "3000",
      "documented": true,
      "name": "reconnectWaitTime",
      "section": "null",
      "type": "integer",
      "value": "0",
      "enabled": true
    }],
    "serverName": "serverName",
    "version": ""
  }'
```

The command should return a response that looks something like this:

**Example response**

```json
{
  "success": true,
  "message": "",
  "data": null
}
```

You can also create stream files using MPEG-TS audio and video [packet identifiers (PIDs)](/content/docs/how-to-control-video-and-audio-pid-and-streamids-for-outgoing-mpeg-ts/index.html), as in the following example. For the value properties in the `MpegtsAudioPID` and `MpegtsVideoPID` blocks, use the values from your encoder.

**Example request**

```bash
curl -X PUT \
  -H 'Accept: application/json; charset=utf-8' \
  -H 'Content-Type: application/json; charset=utf-8' \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/streamfiles/creedence/adv \
  -d '{
    "sourceControlDriver": "",
    "advancedSettings": [{
      "sectionName": "Common",
      "canRemove": false,
      "defaultValue": "null",
      "documented": false,
      "name": "uri",
      "section": "null",
      "type": "string",
      "value": "udp://1.2.3.4:10000",
      "enabled": true
    }, {
      "sectionName": "Common",
      "canRemove": true,
      "defaultValue": "",
      "documented": true,
      "name": "MpegtsAudioPID",
      "section": "null",
      "type": "integer",
      "value": "15",
      "enabled": true
    }, {
      "sectionName": "Common",
      "canRemove": false,
      "defaultValue": "",
      "documented": true,
      "name": "MpegtsVideoPID",
      "section": "null",
      "type": "integer",
      "value": "16",
      "enabled": true
    }],
    "serverName": "serverName",
    "version": ""
  }'
```

## Connect a Stream File

Initiate the connection of a stream file named _creedence_:

**Example request**

```bash
curl -X PUT \
  -H 'Accept:application/json; charset=utf-8' \
  -H 'Content-type:application/json; charset=utf-8' \
  "http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/streamfiles/creedence/actions/connect?connectAppName={appName}&appInstance={instanceName}&mediaCasterType=rtp"
```

## Disconnect a Stream File

Disconnect a stream file:

**Example request**

```bash
curl -X PUT \
  -H 'Accept:application/json; charset=utf-8' \
  -H 'Content-Type:application/json; charset=utf-8' \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/instances/{instanceName}/incomingstreams/{streamfileName}/actions/disconnectStream
```

> **Note:** Stream files must be disconnected before they can be deleted.

## Remove a Stream File

Delete a stream file:

**Example request**

```bash
curl -X DELETE \
  -H 'Accept:application/json; charset=utf-8' \
  http://localhost:8087/v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/streamfiles/{streamfileName}
```
