Skip to content

Write file(s)

This API allows developer to upload a file or update the file by keeping the previous version of the existing file.

Request

POST: {base_url}/:networkID/:appID/files
here the networkID and appID are path parameters.

Note

If you don't want to store a file under any specific app, you just do not need to pass the appID as the path params.

Headers
Learn how to pass authentication headers here.

Parameters

The API uses form-data for uploading files. Below are examples of how to structure the request when uploading a single file.

Parameters Type Description
files array of blobs The file(s) to be uploaded
fileName string The absolute path of the file where the file will be stored.
keepPrevious boolean Set to true to keep the previous version of the file.
createFolders boolean Set to true to create directories if they don’t exist.
encryptionType int The encryption type for the file (see encryption types).

Sample Request

curl --location '{{base_url}}/kapsul/v1/:networkID/files' \
--header 'Authorization: Bearer <DAT Token>' \
--form 'files=@"path_to_your_file"' \
--form 'fileName="path/filename.ext"' \
--form 'keepPrevious="true"' \
--form 'createFolders="true"' \
--form 'encryptionType="0"'

Sample Response

1. When adding a file to Kapsul for the first time.

{
    "code": 200,
    "requestId": "6f2f3b0e-bc6a-42e9-88ca-b7994c897fd3",
    "clientMessage": "file(s) uploaded successfully",
    "data": [
        {
            "active": true,
            "enable": true,
            "version": 1,
            "hash": "bafkreih4joqbifiusp4zjk6ij6jwdiokoxo5mhskjk3z42ybislkofe7ua",
            "filesize": 30086,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T06:00:24.22379836Z",
            "directory": "/motto",
            "path": "/file.ext",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        }
    ]
}

2. When adding a file with same name and keepPrevious is true.

{
    "code": 200,
    "requestId": "6f2f3b0e-bc6a-42e9-88ca-b7994c897fd3",
    "clientMessage": "file(s) uploaded successfully",
    "data": [
        {
            "active": true,
            "enable": true,
            "version": 1,
            "hash": "bafkreih4joqbifiusp4zjk6ij6jwdiokoxo5mhskjk3z42ybislkofe7ua",
            "filesize": 30086,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T06:00:24.22379836Z",
            "directory": "/motto",
            "path": "/file.png",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        },
        {
            "active": true,
            "enable": true,
            "version": 2,
            "hash": "bafkreihq9e84rlop3jvd98ckwioc8a7dmzlkjf5g9p2v7tszucxb2df6ou",
            "filesize": 40088,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T05:58:32.698471076Z",
            "directory": "/motto",
            "path": "/file.png",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        }
    ]
}

Response Parameters

  • code: HTTP status code, 200 indicates success.
  • requestId: Unique identifier for the request.
  • clientMessage: Message confirming the success of the upload.
  • data: Array containing details about the uploaded file(s), including:
    • active: Indicates if the file is active.
    • enable: Indicates if the file is enabled.
    • version: The version number of the file.
    • hash: The hash of the file.
    • filesize: The size of the file in bytes.
    • replication: Number of file copies.
    • encryptionKey: The key used for encryption (empty if not encrypted).
    • lastUpdated: Timestamp of the last update.
    • directory: The directory where the file is stored.
    • path: The path of the file within the directory.
    • nodeAddress: The node address associated with the file.