Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

GET /v1/files/:path/ 

Lists directories and files in the requested path.

Segment

  • :path string: The path to the directories or files

Query String Parameter

  • raw optional: If the path is for a storage device, this will return its raw contents. For example, the request below would be GET /api/v1/files/sd/?raw

Request Example

The example request parameters and headers are set as follows:

  • :path is set to /sd/autorun.brs/

    Code Block
    GET /api/v1/files/sd/autorun.brs/ HTTP/1.1
    Host: {{playerIP}}
    Authorization: {{DigestAuth}}
    Accept: application/json

Response Body

This method returns the metadata for a directory or file (assuming the raw query string parameter is not set):

  • name string: Name of the directory or file

  • type string: Either a directory or file

  • path string: The path, for example, "sd"

  • mime string: mime type (available only for type "file")

  • stat object: Directory stats from the "fs" module

  • fileSize int: The size of the filesystem

  • streamable bool: This is always true for files. If the path is a directory, this is not returned

Response Example

Expand
titleExpand
Code Block
languagejson
{
    "data": {
        "result": {
            "name": "sd/autorun.brs",
            "type": "file",
            "path": "sd/autorun.brs",
            "mime": "application/octet-stream",
            "stat": {
                "dev": 45921,
                "mode": 33277,
                "nlink": 1,
                "uid": 0,
                "gid": 1003,
                "rdev": 0,
                "blksize": 32768,
                "ino": 40,
                "size": 1144340,
                "blocks": 2240,
                "atimeMs": 1699401600000,
                "mtimeMs": 1699423824000,
                "ctimeMs": 1699423824440,
                "birthtimeMs": 0,
                "atime": "2023-11-08T00:00:00.000Z",
                "mtime": "2023-11-08T06:10:24.000Z",
                "ctime": "2023-11-08T06:10:24.440Z",
                "birthtime": "1970-01-01T00:00:00.000Z"
            },
            "fileSize": 1144340,
            "streamable": true
        }
    }
}

Endpoints:

Table of Contents
minLevel1
maxLevel25
include
outlinefalse
indent
stylenone
excludeEndpoints:
typelist
class
printablefalse

POST /v1/files/:path/ 

Renames a file in the path (which should include the file name).

Segment

  • :path string: The path to a file

Request Body

  • name string: The new file name

Request Example

The example request parameters and headers are set as follows:

  • :path is set to /sd/test.txt/

Code Block
POST /api/v1/files/sd/test.txt/ HTTP/1.1
Host: {{playerIP}}
Authorization: {{DigestAuth}}
Accept: application/json
Content-Type: application/json
Content-Length: 21

This is the example request body:

Code Block
languagejson
"name": "newname.txt"

Response

The player will return a 200 success or 404 or 500 error message.

Success Response Body

Code Block
languagejson
{
  "data": {
    "result": {
      "success": true
    }
  }
}

PUT /v1/files/:path/ 

Uploads files or creates directories. The request body needs to be of type multipart/form-data (see RFC 7578). If you add one or more parameters of type file (the name of the parameter does not matter), it will upload the selected file(s). 

To create a directory, remove the form-data from the body, and add the directory as the URL parameter, :path. See the example below.

Segment

  • :path string: The path is the folder in which you want to upload the file.

Request Body

  • files object[]:

    • fileName string: The name of the file

    • fileContents string: The content of the file. It can be provided as plain text or as Data URL.

    • fileType string: Mime type

Request Example (File)

The example request parameters and headers are set as follows:

  • path is set to sd

Code Block
PUT /api/v1/files/sd/ HTTP/1.1
Host: {{playerIP}}
Authorization: {{DigestAuth}}
Content-Length: 227
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="/path/to/file/test.txt"
Content-Type: text/plain

(data)
------WebKitFormBoundary7MA4YWxkTrZu0gW--

Response Body

  • success bool: A flag that indicates if the operation succeeded or not

  • results string[]: The names of the files that were successfully created

Response Example (Plain Text File)

Code Block
languagejson
{
    "data": {
        "result": {
            "success": true,
            "results": [
                "test.txt"
            ]
        }
    }
}

Request Example (Folder)

Code Block
PUT /api/v1/files/sd/testfolder/
Host: {{playerIP}}
Authorization: {{DigestAuth}}
Accept: application/json, application/vnd.bsn.error+json

Response Example (Folder)

Code Block
languagejson
{
    "data": {
        "result": {
            "success": true
        }
    }
}

 

DELETE /v1/files/:path/ 

Removes a file or directory

Segment

  • :path string: The path to the file or directory

Request Example

The example request parameters and headers are set as follows:

  • :path is set to sd/test.txt

Code Block
DELETE /api/v1/files/sd/test.txt/ HTTP/1.1
Host: {{playerIP}}
Authorization: {{DigestAuth}}
Accept: application/json

Response

The player will return a 200 success or 404 or 500 error message.

Success Response Body

Code Block
languagejson
{
  "data": {
    "result": {
      "success": true
    }
  }
}