IoT File Java 客户端
简介
IoT File Java 客户端允许用户管理与实体实例相关的文件。有关该服务的更多信息,请参见 IoT File Service。
提示
在 IoT 环境中,assets 指 entity,aspects 指 propertyset。以下示例中的占位符由尖括号 < >
表示。
文件操作
客户端名称:FileServiceClient
创建或更新文件
本部分展示了使用指定路径中为 asset 提供的内容创建或更新文件的两种选项。
// Construct the FileServiceClient object
FileServiceClient file_service_client = FileServiceClient.builder()
.mindsphereCredentials(<credentials>)
.restClientConfig(<config>)
.build();
try {
file_service_client.putFile(<bytes_array>, <entity_id>, <file_path>, <ifMatch>, <timestamp>, <description>, <type>);
} catch (MindsphereException e) {
// Exception handling
}
或者,使用 PutFileRequest
模型。
// Construct the FileServiceClient object as shown above
PutFileRequest request_object = new PutFileRequest();
request_object.setFile(<bytes_array>);
request_object.setEntityId(<entity_id>);
request_object.setFilepath(<file_path>);
request_object.setTimestamp("2018-09-10T05:03:42.363Z");
request_object.setDescription("lorem test3");
request_object.setType("txt");
try {
file_service_client.putFile(request_object);
} catch (MindsphereException e) {
// Exception handling
}
读取文件
本部分展示了从指定路径中读取 asset 的文件的两种选项。
// Construct the FileServiceClient object as shown above
byte[] file_data;
try {
file_data = file_service_client.getFile(<entity_id>, <file_path>, <ifNoneMatch>);
} catch (MindsphereException e) {
// Exception handling
}
或者,使用 GetFileRequest
模型。
// Construct the FileServiceClient object as shown above
GetFileRequest request_object = new GetFileRequest();
request_object.setEntityId(<entity_id>);
request_object.setFilepath(<file_path>);
byte[] fileData;
try {
fileData = file_service_client.getFile(request_object);
} catch (MindsphereException e) {
// Exception handling
}
删除文件
本部分展示了从指定路径中删除 asset 的文件的两种选项。
// Construct the FileServiceClient object as shown above
try {
file_service_client.deleteFile(<entity_id>, <file_path>)
} catch (MindsphereException e) {
// Exception handling
}
或者,使用 DeleteFileRequest
模型。
// Construct the FileServiceClient object as shown above
DeleteFileRequest request_object = new DeleteFileRequest();
request_object.setEntityId(<entity_id>);
request_object.setFilepath(<file_path>);
try {
file_service_client.deleteFile(request_object)
} catch (MindsphereException e) {
// Exception handling
}
搜索文件
本部分展示了在指定路径中搜索 asset 的一个或多个文件的两种选项。
// Construct the FileServiceClient object as shown above
List<File> file_search_response;
try {
file_search_response = file_service_client.searchFiles(<entity_id>, <offset>, <limit>, <count>, <order>, <filter>);
} catch (MindsphereException e) {
// Exception handling
}
或者,使用 GetFileRequest
模型。
// Construct the FileServiceClient object as shown above
SearchFilesRequest request_object = new SearchFilesRequest();
request_object.setEntityId(<entity_id>);
List<File> file_search_response;
try {
file_search_response = file_service_client.searchFiles(request_object);
} catch (MindsphereException e) {
// Exception handling
}
列出多部分上传
本部分描述了列出多部分上传的两个选项。
// Construct the FileServiceClient object as shown above
List<Fileslist> file_list;
try {
file_list = file_service_client.getFileList(<entity_id>, <file_path>);
} catch (MindsphereException e) {
// Exception handling
}
或者,使用 GetFileListRequest
模型。
//Create client object "fileServiceClient" as shown above
GetFileListRequest request_object = new GetFileListRequest();
request_object.setEntityId(<entity_id>);
request_object.setFilepath(<file_path>);
List<Fileslist> file_list;
try {
file_list = file_service_client.getFileList(request_object);
} catch (MindsphereException e) {
// Exception handling
}
启动新的多部分上传
为指定路径中的 asset 启动新的多部分文件上载。
// Construct the FileServiceClient object as shown above
// Create the request object
PutFileRequest request_object = new PutFileRequest().entityId(<entity_id>).filepath(<file_path>);
try {
file_service_client.initiateMultiPartUpload(request_object);
} catch(MindsphereException e) {
// Exception handling
}
上传多部分上传的部分
使用 PutFileRequest
模型上传带有在指定路径中提供的内容并已启动的多部分上传的部分。
// Construct the PutFileRequest object
PutFileRequest request_object = new PutFileRequest()
.entityId(<entity_id>).filepath(<file_path>)
.type(<type_of_file>).file(<file_as_bytes>).part(<part_no>)
.timestamp(<timestamp>).description(<description>);
try {
file_service_client.createMultiPartFile(request_object);
} catch(MindsphereException e) {
// Exception handling
}
完成多部分上传
使用 PutFileRequest
模型完成多部分上传。
// Construct the PutFileRequest object as shown above
//Create the request object
PutFileRequest request_object = new PutFileRequest().entityId(<entity_id>).filepath(<file_path>);
try {
file_service_client.completeMultiPartUpload(request_object);
} catch(MindsphereException e) {
// Exception handling
}
中止多部分上传
使用 PutFileRequest
模型中止多部分上传。
// Construct the PutFileRequest object as shown above
//Create the request object
PutFileRequest request_object = new PutFileRequest().entityId(<entity_id>).filepath(<file_path>);
try {
file_service_client.abortMultiPartUpload(request_object);
} catch (MindsphereException e) {
// Exception handling
}
启动现有多部分上传的更新
要更新现有的多部分上传,需要为指定路径中的 asset 重新启动多部分上传。请注意 ifMatch
参数是此动作的强制参数。
// Construct the PutFileRequest object as shown above
//Create the request object
PutFileRequest request_object = new PutFileRequest().entityId(<entity_id>)
.filepath(<file_path>).ifMatch(<ifMatch>);
try {
file_service_client.initiateMultiPartUpload(request_object);
} catch(MindsphereException e) {
// Exception handling
}
更新现有多部分上传
使用 PutFileRequest
模型更新带有在指定路径中提供的内容的现有多部分上传的部分。请注意 ifMatch
参数是此动作的强制参数。
// Construct the PutFileRequest object as shown above
//Create the request object
PutFileRequest request_object = new PutFileRequest()
.entityId(<entity_id>).filepath(<file_path>).ifMatch(<ifMatch>)
.type(<type_of_file>).file(<file_as_bytes>).part(<part_no>)
.timestamp(<timestamp>).description(<description>);
try {
file_service_client.updateMultiPartFile(request_object);
} catch (MindsphereException e) {
// Exception handling
}
完成现有多部分上传的更新
使用 PutFileRequest
模型完成现有多部分上传的更新。请注意 ifMatch
参数是此动作的强制参数。
// Construct the PutFileRequest object as shown above
//Create the request object
PutFileRequest request_object = new PutFileRequest().entityId(<entity_id>)
.filepath(<file_path>).ifMatch(<ifMatch>);
try {
file_service_client.initiateMultiPartUpload(request_object);
} catch(MindsphereException e) {
// Exception handling
}
中止现有多部分上传的更新
使用 PutFileRequest
模型中止现有多部分文件上传的更新。请注意 ifMatch
参数是此动作的强制参数。
// Construct the PutFileRequest object as shown above
//Create the request object
PutFileRequest request_object = new PutFileRequest().entityId(<entity_id>).filepath(<file_path>).ifMatch(<ifMatch>);
try {
file_service_client.abortMultiPartUpload(request_object);
} catch (MindsphereException e) {
// Exception handling
}
还有问题?
除非另行声明,该网站内容遵循MindSphere开发许可协议.