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.

Hint

In the IoT context, assets are referred to as entity and aspects as propertyset.
Placeholders in the following samples are indicated by angluar 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
// 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.

1
2
3
4
5
6
7
// 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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
// 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
}

Any questions left?

Ask the community


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