Skip to content

IoT File Services Client for Node.js

Introduction

The IoT File Services Node.js client allows you to manage files related to assets. Refer to IoT File Service for more information about the service.

Further implementation of the IOT File Service SDK library has been shown in a sample project that you can download and test in local or on Insights Hub application. Please refer to this repository: industrial-iot-node-sdk-examples

Hint

In the IoT context, assets are referred to as entity and aspects as propertyset.
Placeholders in the following samples are indicated by angle brackets < >.

File Operations

Client name: FileServiceClient

Create or Update a File

Create or update a file with the provided content for an asset in the specified path.

// Import the mindsphere-sdk-node-core module and require AppCredentials and ClientConfig
let AppCredentials = require('mindsphere-sdk-node-core').AppCredentials;
let ClientConfig = require('mindsphere-sdk-node-core').ClientConfig;

// Import the iotfileservices module and require FileServiceClient
const FileServiceClient = require('iotfileservices-sdk').FileServiceClient;


// Construct the ClientConfig and AppCredentials objects
let config = new ClientConfig();
let credentials = new AppCredentials();

// Construct the FileServiceClient object
let file_service_client = new FileServiceClient(config, credentials);

try {
  const request_object = {
    file: <file>,
    entityId: <entity_id>,
    filepath: <file_path>,
    ifMatch: <ifMatch>,
    timestamp: <timestamp>,
    description: <description>,
    type: <type>
  };

  await file_service_client.putFile(request_object);
} catch (ex) {
  // Exception handling
}

Read a File

Read a file for an asset from the specified path.

// Construct the FileServiceClient object as shown above

let file_data;
try {
  const request_object = {
    entityId: <entity_id>,
    filepath: <file_path>,
    ifNoneMatch: <ifNoneMatch>
  };

  file_data = await file_service_client.getFile(request_object);
} catch (ex) {
    // Exception handling
}

Delete a File

Delete a file from an asset at the specified path.

// Construct the FileServiceClient object as shown above

try {
  await file_service_client.deleteFile({ entityId: <entity_id>, filepath: <file_path> });
} catch (ex) {
  // Exception handling
}

Search a File

Search one or multiple files of an asset in the specified path.

// Construct the FileServiceClient object as shown above

let file_search_response;
try {
  const request_object = {
    entityId: <entity_id>,
    offset: <offset>,
    limit: <limit>,
    count: <count>,
    order: <order>,
    filter: <filter>
  };

  file_search_response = await file_service_client.searchFiles(request_object);
} catch (MindsphereException e) {
  // Exception handling
}

Last update: February 23, 2024

Except where otherwise noted, content on this site is licensed under the Development License Agreement.