CRecordFileStoreAddLocalFile: Import Local File into a FileStore

This message imports a local file into the FileStore of a nyssr.net node.

This message belongs to the FileStore API. The message is a nanoservice of the SYSTEM namespace.

{
  "id": "e62b8dea-1596-415a-b054-3fb15fd4d354",
  "name": "FILE_STORE_ADD_LOCAL_FILE",
  "description": "Add a local file to the file store.",
  "isNanoService": "true",
  "type": "REQUEST",
  "namespaces": "SYSTEM",
  "slots": [
    {
      "key": "1",
      "name": "PATH",
      "direction": "REQUEST",
      "presenceConstraint": "MANDATORY",
      "type": "STRING",
      "description": "The path of the file."
    },
    {
      "key": "2",
      "name": "RELATIVE_DESTINATION_PATH",
      "direction": "REQUEST",
      "presenceConstraint": "MANDATORY",
      "type": "STRING",
      "description": "The relative path of the file in the storage directory (without file name)."
    }
  ]
}

Slot Description

Key Name Direction Presence Constraint Type Description
1 PATH REQUEST MANDATORY STRING The path of the file to import.
2 RELATIVE_DESTINATION_PATH REQUEST MANDATORY STRING All files in FileStore are identified by a relative path to the FileStore base directory.
Example: “images/admin.jpeg”

While the relative path of the file serves as the key to finding it, the file path is an absolute path where the file can be found before import. Thus, the relative path may significantly differ from the current path.

Usage

Request

private void addLocalFile(@NotNull final File aFile) throws CException
{
    final CEnvelope env = CEnvelope.forLocalNanoService(CRecordFileStoreAddLocalFile.class);

    final CRecord record = CRecordFileStoreAddLocalFile.create();
    CRecordFileStoreAddLocalFile.setPath(record,
                                         aFile.getPath());
    CRecordFileStoreAddLocalFile.setRelativeDestinationPath(record,
                                                            "urgent/news.txt");
    sendRequest(env,
                record);
}
]

After import, the file is located in the storage directory as storage/FileStore/indexed/urgent/news.txt._32_[base32-hash]. Slashes (/) or backslashes (\\) can be used as path separators.

Catch the response

In the constructor:

addMessageHandler(CRecordFileStoreAddLocalFile.ID,
                  this::asyncAddLocalFile);

Message handler

private boolean asyncAddLocalFile(@NotNull final CEnvelope aEnvelope,
                                  @NotNull final CRecord aRecord)
{
    if (aEnvelope.isAnswer())
    {
        if (aEnvelope.getResult()
                     .hasSuccess())
        {
            ...
        }
        else
        {
            ...
        }
        return true;
    }
    else
    {
        return false;
    }
}

Record Usage

In nyssr.net, we typically don't exchange interfaces between projects. Instead, we use platform-independent Records to describe message formats.

One or more descriptions of these Records are stored in the JSON or XML format as record.json or record.xml within a directory. The Record Generator, an included Swing tool, generates helper classes from these files. These classes can then be used to type-safely write or read messages.

See also