Skip to content

Write files under folder (Coming soon)

Request path

{{base_url}}/moibit/v1/:networkID/:appID/files

Request type - POST

Description

This API allows you to add a new file, upload a new version of an existing file, or add multiple files or directories to MOI Bit.

Note

If you want to store a file under a specific app, you should provide the appID in the request params. If you do not wish to associate the file with any app, you may leave appID blank.

Headers

When making a request to this endpoint, you need to include the following header:

  • Authorization: <DAT Token>

For more details on obtaining and using the DAT Token, check out MOI Bit Auth Token.

Parameters

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

Parameters Type Description Optional
files Array of Blobs The files to be uploaded No
dirPath 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. Yes
createFolders boolean Set to true to create directories if they don’t exist. Yes
replication boolean Set to true to create directories if they don’t exist. Yes
encryptionType int The encryption type for the file (see encryption types). Yes

Sample Request

curl --location '{{base_url}}/moibit/v1/:networkID/files' \
--header 'Authorization: Bearer <DAT Token>' \
--form 'files=@"path_to_your_first_file"' \
--form 'files=@"path_to_your_second_file"' \
--form 'keepPrevious="true"' \
--form 'createFolders="true"' \
--form 'encryptionType="0"'

Sample Response

1. When adding set of file to moibit for the first time.

{
    "code": 200,
    "requestId": "f6f4098a-37ea-4205-9a26-a2a264bd8dee",
    "clientMessage": "file(s) uploaded successfully",
    "data": [
        {
            "active": true,
            "enable": true,
            "version": 1,
            "hash": "bafkreiba5bwcwojzxnm4tyvst5ymlzhvw26clmrbtgcmybtwkdxpqeozu4",
            "filesize": 30086,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T05:58:32.573799297Z",
            "directory": "/",
            "path": "/lmao.png",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        },
        {
            "active": true,
            "enable": true,
            "version": 1,
            "hash": "bafkreicpfte5nzzdwp5v56luubt6eoxrj4mofixgu7mcpi6nexnhybxeg4",
            "filesize": 4128,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T05:58:32.698471076Z",
            "directory": "/",
            "path": "/XOOG.png",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        },
    ]
}

2. When adding set of files with same name and keepPrevious is true.

{
    "code": 200,
    "requestId": "f6f4098a-37ea-4205-9a26-a2a264bd8dee",
    "clientMessage": "file(s) uploaded successfully",
    "data": [
        {
            "active": true,
            "enable": true,
            "version": 1,
            "hash": "bafkreiba5bwcwojzxnm4tyvst5ymlzhvw26clmrbtgcmybtwkdxpqeozu4",
            "filesize": 30086,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T05:58:32.573799297Z",
            "directory": "/",
            "path": "/image1.png",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        },
        {
            "active": true,
            "enable": true,
            "version": 2,
            "hash": "bafkrei7hjt2znx3r4plqs0vj5w8mdu6a9fg0i1o7c8k4y2rmp",
            "filesize": 50042,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T06:00:24.22379836",
            "directory": "/",
            "path": "/image1.png",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        },
        {
            "active": true,
            "enable": true,
            "version": 1,
            "hash": "bafkreicpfte5nzzdwp5v56luubt6eoxrj4mofixgu7mcpi6nexnhybxeg4",
            "filesize": 4128,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T05:58:32.698471076Z",
            "directory": "/",
            "path": "/image2.png",
            "nodeAddress": "0x994f5A780B9BBBcdef425EE5905b90Ffd3Ac4f87"
        },
        {
            "active": true,
            "enable": true,
            "version": 2,
            "hash": "bafkrei7hjt2znx3r4plqs0vj5w8mdu6a9fg0i1o7c8k4y2rmp",
            "filesize": 5006,
            "replication": 2,
            "encryptionKey": "",
            "lastUpdated": "2024-09-01T06:00:24.22379836",
            "directory": "/",
            "path": "/image2.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.