Skip to content

Node.js 的 IoT File Services Client

简介

IoT File Services Node.js 客户端允许您管理和 assets 相关的文件。有关该服务的更多信息请参考 IoT File Service

提示

在 IoT 环境中,assetsentityaspectspropertyset
下面示例中的占位符用尖括号 < > 表示。

文件操作

客户端名称: FileServiceClient

创建或者更新一个文件

使用指定路径中的 asset 提供的内容创建或更新文件。

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

读取文件

读取指定路径中 asset 的文件。

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

删除文件

删除指定路径中 asset 的文件。

// Construct the FileServiceClient object as shown above

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

查询文件

删除指定路径中 asset 的一个或多个文件。

// 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: March 22, 2023