Logo

Sign InGet Started

Docs

Docs

Kernex Uploads

Getting Started

Uploads are a way to store files in Kernex's cloud storage. They are working the same exact way as the Resources, but they are optimized for file storage. Unlike the resources, that are defined by you, the uploads are managed by Kernex and they have a fixed structure.


Please check the Rest API section for more information about how to interact with the API.

Authorization

Please follow the REST API Authorization section for more information about how to authorize your requests.

Upload Structure

The upload structure is the following:

  • _id (string, readonly): the unique identifier of the upload
  • url (string, readonly): the absolute URL of the file, that you can use to access the file.This is the URL that you should use when you want to display the file in your website.
  • title (string): the title of the upload
  • description (string): description of the upload
  • name (string, readonly): the name of the file
  • fileId (number, readonly): an id of the file (used internally by Kernex), in the storage bucket.
  • ext (string, readonly): the extension of the file
  • contentType (string, readonly): the content type of the file
  • createdAt (string, readonly): the date when the upload was created
  • updatedAt (string, readonly): the date when the upload was updated

Base Endpoint URL

The base endpoint URL for the uploads is:

https://api.kernex.io/api/v1/:appId/uploads

Create Upload

Create a new Upload entry.

The only required field when you create a new upload, is thefile field, which has to be a data URI string

URL

https://api.kernex.io/api/v1/:appId/uploads

HTTP Method

POST

Headers

x-api-key: your-api-key
content-type: application/json

Body:

{
  "title": "Black Shirt",
  "description": "Black shirt with a white dragon",
  "file": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAS..."
}

Request Example

curl "https://api.kernex.io/api/v1/:appId/uploads" \
 -X POST \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key" \
-d "{\"title\":\"Black Shirt\",\"description\":\"Black shirt with a white dragon\",\"file\":\"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAS...\"}"

Response Example

{
  "_id": "entryId",
  "createdAt": "2024-05-11T13:02:14.148Z",
  "updatedAt": "2024-05-11T13:02:14.148Z",
  "title": "Black Shirt",
  "description": "Black shirt with a white dragon",
  "name": "black-shirt.jpg",
  "ext": "jpg",
  "contentType": "image/jpeg",
  "url": "https://kernex.fra1.cdn.digitaloceanspaces.com/apps/your-app-id/uploads/entryId/black-shirt.jpg"
}

Get Upload

Get a Upload entry.

URL

https://api.kernex.io/api/v1/:appId/uploads/:_id

HTTP Method

GET

Headers

x-api-key: your-api-key
content-type: application/json

Request Example

curl "https://api.kernex.io/api/v1/:appId/uploads/:_id" \
 -X GET \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key"

Response Example

{
  "_id": "entryId",
  "createdAt": "2024-05-11T13:02:14.148Z",
  "updatedAt": "2024-05-11T13:02:14.148Z",
  "title": "Black Shirt",
  "description": "Black shirt with a white dragon",
  "name": "black-shirt.jpg",
  "ext": "jpg",
  "contentType": "image/jpeg",
  "url": "https://kernex.fra1.cdn.digitaloceanspaces.com/apps/your-app-id/uploads/entryId/black-shirt.jpg"
}

Find Uploads

Please follow the REST API Find Resources section for more information about how to use the find method.

URL

https://api.kernex.io/api/v1/:appId/uploads

Params

{
  "$limit": 10,
  "$skip": 0,
  "$select": [
    "title"
  ],
  "$sort": {
    "title": 1
  }
}

HTTP Method

GET

Headers

x-api-key: your-api-key
content-type: application/json

Request Example

curl "https://api.kernex.io/api/v1/:appId/uploads?%24limit=10&%24skip=0&%24select%5B0%5D=title&%24sort%5Btitle%5D=1" \
 -X GET \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key"

Response Example

{
  "data": [
    {
      "_id": "entryId",
      "createdAt": "2024-05-11T13:02:14.148Z",
      "updatedAt": "2024-05-11T13:02:14.148Z",
      "title": "Hello"
    },
    {
      "_id": "entryId",
      "createdAt": "2024-05-11T13:02:14.148Z",
      "updatedAt": "2024-05-11T13:02:14.148Z",
      "title": "Welcome"
    }
  ],
  "total": 2,
  "limit": 10,
  "skip": 0
}

Patch Upload

Patch a Upload entry. Patching will update the specified fields in the data, while not changing the unspecified ones.

URL

https://api.kernex.io/api/v1/:appId/uploads/:uploadId

HTTP Method

PATCH

Headers

x-api-key: your-api-key
content-type: application/json

Body:

{
  "title": "New title",
  "description": "New Description"
}

Request Example

curl "https://api.kernex.io/api/v1/:appId/uploads/:uploadId" \
 -X PATCH \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key" \
-d "{\"title\":\"New title\",\"description\":\"New Description\"}"

Response Example

{
  "_id": "entryId",
  "createdAt": "2024-05-11T13:02:14.148Z",
  "updatedAt": "2024-05-11T13:02:14.148Z",
  "title": "Black Shirt",
  "description": "Black shirt with a white dragon",
  "name": "black-shirt.jpg",
  "ext": "jpg",
  "contentType": "image/jpeg",
  "url": "https://kernex.fra1.cdn.digitaloceanspaces.com/apps/your-app-id/uploads/entryId/black-shirt.jpg"
}

Update Upload

Update a Upload entry. Updating will update the entry entirely. If you want to update only some fields, then use the patch method.

RECOMMENDATION: we recommend you to use the patch method instead of update.

URL

https://api.kernex.io/api/v1/:appId/uploads/:uploadId

HTTP Method

PUT

Headers

x-api-key: your-api-key
content-type: application/json

Body:

{
  "title": "New title",
  "description": "New Description"
}

Request Example

curl "https://api.kernex.io/api/v1/:appId/uploads/:uploadId" \
 -X PUT \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key" \
-d "{\"title\":\"New title\",\"description\":\"New Description\"}"

Response Example

{
  "_id": "entryId",
  "createdAt": "2024-05-11T13:02:14.148Z",
  "updatedAt": "2024-05-11T13:02:14.148Z",
  "title": "New Title"
}

Remove Upload

Remove a Upload entry.

URL

https://api.kernex.io/api/v1/:appId/uploads/:uploadId

HTTP Method

DELETE

Headers

x-api-key: your-api-key
content-type: application/json

Request Example

curl "https://api.kernex.io/api/v1/:appId/uploads/:uploadId" \
 -X DELETE \
-H "Content-Type: application/json" \
-H "x-api-key: your-api-key"

Response Example

{
  "_id": "entryId",
  "createdAt": "2024-05-11T13:02:14.148Z",
  "updatedAt": "2024-05-11T13:02:14.148Z",
  "title": "Hello"
}