Files | Flextype

Files

Rest API

The Flextype Files API organized around Representational State Transfer (REST) for delivering files from Flextype to apps, websites and other. Folders are delivered as JSON data.

Endpoints

Method Endpoint Description
GET /api/files Fetch file(files)
POST /api/files Upload file
PUT /api/files Rename file
DELETE /api/files Delete file
PATCH /api/files/meta Updates file meta information
POST /api/files/meta Add file meta information
DELETE /api/files/meta Delete file meta information

Fetch single file

Request
GET /api/files?id=YOUR_FILES_ID&token=YOUR_FILES_TOKEN
Query
Name Description
path REQUIRED Files path.
token REQUIRED Valid Files Token.
Result

Returns the item object for the given unique identifier.

Examples

Fetch file entries/movies/sg-1/season-5/episode-21/cover.jpg

Request
GET /api/files?id=entries/movies/sg-1/season-5/episode-21/cover.jpg&token=6f047babd1894064fbf7662080a9a2f0
Response
200 OK
{
    "data": {
        "title": "Episode 21",
        "filename": "cover.jpg",
        "basename": "cover",
        "extension": "jpg",
        "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21",
        "url": "project/uploads/entries/movies/sg-1/season-5/episode-21/cover.jpg",
        "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21/cover.jpg"
    }
}

Fetch files collection

Request
GET /api/files?id=YOUR_FILES_FOLDER_ID&collection=true&token=YOUR_FILES_TOKEN
Query
Name Description
path REQUIRED Files folder path.
token REQUIRED Valid Folders Token.
Result

Returns an array of item objects.

Examples

Fetch Movies Folders Collection entries/movies/sg-1/season-5/episode-21

Request
GET /api/files?id=entries/movies/sg-1/season-5/episode-21&token=6f047babd1894064fbf7662080a9a2f0
Response
200 OK
{
    "data": {
        "cover.jpg": {
            "title": "Episode 21",
            "filename": "cover.jpg",
            "basename": "cover",
            "extension": "jpg",
            "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21",
            "url": "project/uploads/entries/movies/sg-1/season-5/episode-21/cover.jpg",
            "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21/cover.jpg"
        }
    }
}

Upload file

Request
POST /api/files
Body
Name Description
folder REQUIRED The folder you're targetting.
file REQUIRED Raw file data (multipart/form-data).
token REQUIRED Valid Files token.
access_token REQUIRED Valid Access token.
Result

Returns the file object for the file that was just uploaded.

Examples

Upload new file to entries/movies/sg-1/season-5/episode-21

Request
POST /api/files
Body
curl -i -X POST \
  -H "Content-Type: multipart/form-data" \
  -F "token=efe1e36e4d60fcd547e22eb9f795dff92" \
  -F "access_token=efe1e36e4d60fcd547e22eb9f795dff91" \
  -F "folder=entries/movies/sg-1/season-5/episode-21" \
  -F "file=@/users/awilum/documents/new-covers/new-cover.jpg" \
  http://localhost:8888/flextype/api/files
Response
200 OK
{
  "data": {
    "title": "New Cover",
    "description": "",
    "type": "image/jpeg",
    "filesize": 342298,
    "uploaded_on": 1596107422,
    "exif": {
      "html": "width=\"1600\" height=\"900\"",
      "Height": 900,
      "Width": 1600,
      "IsColor": 1
    },
    "filename": "new-cover.jpg",
    "basename": "new-cover",
    "extension": "jpg",
    "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21",
    "url": "project/uploads/entries/movies/sg-1/season-5/episode-21/new-cover.jpg",
    "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21/new-cover.jpg"
  }
}

Rename file

Request
PUT /api/files
Body
Name Description
path REQUIRED Unique identifier of the file.
new_path REQUIRED New Unique identifier of the file.
token REQUIRED Valid Files token.
access_token REQUIRED Valid Access token.
Result

Returns the folders object for the file that was just renamed

Examples

Rename file entries/movies/sg-1/season-5/episode-21/cover.jpg to the entries/movies/sg-1/season-5/episode-21/new-cover.jpg

Request
PUT /api/files
Body
{
    "path": "entries/movies/sg-1/season-5/episode-21/cover.jpg",
    "new_path": "entries/movies/sg-1/season-5/episode-21/new-cover.jpg",
    "token": "f3acf199a9ac120d3bfd604e1e382456",
    "access_token": "bbc4417d171e38099bd129aeca279018"
}
Response
200 OK
{
    "data": {
        "title": "Episode 21",
        "filename": "new-cover.jpg",
        "basename": "new-cover",
        "extension": "jpg",
        "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21",
        "url": "project/uploads/entries/movies/sg-1/season-5/episode-21/new-cover.jpg",
        "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21/new-cover.jpg"
    }
}

Move file entries/movies/sg-1/season-5/episode-21/cover.jpg to the entries/movies/sg-1/season-5/cover.jpg

Request
PUT /api/files
Body
{
    "path": "entries/movies/sg-1/season-5/episode-21/cover.jpg",
    "new_path": "entries/movies/sg-1/season-5/cover.jpg",
    "token": "f3acf199a9ac120d3bfd604e1e382456",
    "access_token": "bbc4417d171e38099bd129aeca279018"
}
Response
200 OK
{
    "data": {
        "title": "Episode 21",
        "filename": "cover.jpg",
        "basename": "cover",
        "extension": "jpg",
        "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5",
        "url": "project/uploads/entries/movies/sg-1/season-5/cover.jpg",
        "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/new-cover.jpg"
    }
}

Copy File

Request
PUT /api/files/copy
Body
Name Description
path REQUIRED Unique identifier of the file.
new_path REQUIRED New Unique identifier of the file.
token REQUIRED Valid Folders token.
access_token REQUIRED Valid Access token.
Result

Returns the file object for the file that was just copied.

Examples

Copy for entry entries/movies/sg-1/season-5/cover.jpg to entries/movies/sg-1/season-5/episode-21/cover.jpg

Request
PUT /api/files/copy
Body
{
    "path": "entries/movies/sg-1/season-5/cover.jpg",
    "new_path": "entries/movies/sg-1/season-5/episode-21/cover.jpg",
    "token": "f3acf199a9ac120d3bfd604e1e382456",
    "access_token": "bbc4417d171e38099bd129aeca279018"
}
Response
200 OK
{
    "data": {
        "title": "Episode 21",
        "filename": "cover.jpg",
        "basename": "cover",
        "extension": "jpg",
        "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21",
        "url": "project/uploads/entries/movies/sg-1/season-5/episode-21/cover.jpg",
        "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/episode-21/cover-4.jpg"
    }
}

Delete file

Request
DELETE /api/files
Body
Name Description
path REQUIRED Unique identifier of the file.
token REQUIRED Valid Files token.
access_token REQUIRED Valid Access token.
Result

Returns an empty body with HTTP status 204

Examples

Delete entry entries/movies/sg-1/season-5/episode-21/new-cover.jpg

Request
DELETE /api/files
Body
{
    "id": "entries/movies/sg-1/season-5/episode-21/new-cover.jpg",
    "token": "f3acf199a9ac120d3bfd604e1e382456",
    "access_token": "bbc4417d171e38099bd129aeca279018"
}

Update File Meta

Request
PUT /api/files
Body
Name Description
path REQUIRED Unique identifier of the file.
field REQUIRED Field name.
value REQUIRED Field value.
token REQUIRED Valid Files token.
access_token REQUIRED Valid Access token.
Result

Returns the file object for the file that was just updated.

Examples

Update title for file entries/movies/sg-1/season-5/cover.jpg

Request
PATCH /api/files/meta
Body
{
    "field": "title",
    "value": "Season 5",
    "path": "entries/movies/sg-1/season-5/cover.jpg",
    "new_path": "entries/movies/sg-1/season-5/episode-21/cover.jpg",
    "token": "f3acf199a9ac120d3bfd604e1e382456",
    "access_token": "bbc4417d171e38099bd129aeca279018"
}
Response
200 OK
{
    "data": {
        "title": "Season 5",
        "filename": "cover.jpg",
        "basename": "cover-4",
        "extension": "jpg",
        "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5",
        "url": "project/uploads/entries/movies/sg-1/season-5/cover.jpg",
        "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/cover.jpg"
    }
}

Add File Meta

Request
POST /api/files
Body
Name Description
path REQUIRED Unique identifier of the file.
field REQUIRED Field name.
value REQUIRED Field value.
token REQUIRED Valid Files token.
access_token REQUIRED Valid Access token.
Result

Returns the file object for the file that was just updated.

Examples

Add tags for file entries/movies/sg-1/season-5/cover.jpg

Request
PATCH /api/files/meta
Body
{
    "field": "tags",
    "value": "sg-1, season-5",
    "path": "entries/movies/sg-1/season-5/cover.jpg",
    "new_path": "entries/movies/sg-1/season-5/episode-21/cover.jpg",
    "token": "f3acf199a9ac120d3bfd604e1e382456",
    "access_token": "bbc4417d171e38099bd129aeca279018"
}
Response
200 OK
{
    "data": {
        "title": "Season 5",
        "tags": "sg-1, season-5",
        "filename": "cover.jpg",
        "basename": "cover-4",
        "extension": "jpg",
        "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5",
        "url": "project/uploads/entries/movies/sg-1/season-5/cover.jpg",
        "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/cover.jpg"
    }
}

Delete File Meta

Request
DELETE /api/files
Body
Name Description
path REQUIRED Unique identifier of the file.
field REQUIRED Field name.
token REQUIRED Valid Files token.
access_token REQUIRED Valid Access token.
Result

Returns the file object for the file that was just updated.

Examples

Delete tags meta field for file entries/movies/sg-1/season-5/cover.jpg

Request
DELETE /api/files/meta
Body
{
    "field": "tags",
    "path": "entries/movies/sg-1/season-5/cover.jpg",
    "new_path": "entries/movies/sg-1/season-5/episode-21/cover.jpg",
    "token": "f3acf199a9ac120d3bfd604e1e382456",
    "access_token": "bbc4417d171e38099bd129aeca279018"
}
Response
200 OK
{
    "data": {
        "title": "Season 5",
        "filename": "cover.jpg",
        "basename": "cover-4",
        "extension": "jpg",
        "dirname": "/htdocs/flextype/project/uploads/entries/movies/sg-1/season-5",
        "url": "project/uploads/entries/movies/sg-1/season-5/cover.jpg",
        "full_url": "http://localhost:8888/flextype/project/uploads/entries/movies/sg-1/season-5/cover.jpg"
    }
}
Language: en, ru