CRecordFileStoreAddLocalFile

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.",
  "isService": "true",
  "namespaces": "SYSTEM",
  "slots": [
    {
      "key": "1",
      "name": "PATH",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The path of the file."
    },
    {
      "key": "2",
      "name": "RELATIVE_DESTINATION_PATH",
      "direction": "REQUEST",
      "mandatory": "true",
      "type": "STRING",
      "description": "The relative path of the file in the storage directory (without file name)."
    }
  ]
}

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;
    }
}

nyssr.net - Innovative Distributed System