hz/cloud-platform/cctp-dw/README.md

150 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# nk-files
CCTP产品的文件服务默认端口9631
## 命令脚本
Linux环境下执行 nk-ms.sh start|stop|restart|status
Windows环境下执行 start.bat (暂未提供)
## 使用方式
### 上传文件:
WEB页面的形式
编辑一个html页面代码如下
```html
<!DOCTYPE html>
<html lang="zh_CN">
<head>
<meta charset="UTF-8">
<title>测试文件上传功能</title>
</head>
<body>
<form action="http://192.168.0.40:9631/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" value="上传文件"/>
</form>
</body>
</html>
```
使用浏览器打开该页面通过页面表单的形式上传文件上传成功后会返回文件的唯一ID返回的报文如下
```json
{
"success":true,
"code":"000000",
"message":"接口调用成功",
"timestamp":1585132341906,
"data":"5c2e20f0cfd04ba5a5cc86ed128c9564"
}
```
JAVA编码的形式
引用Maven依赖
```xml
<dependency>
<groupId>net.northking.commons</groupId>
<artifactId>nk-files-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
```
JAVA示例代码如下:
```java
String ipAddress = "192.168.0.40";
int port = 9631;
// File file = new File("F:\\工作笔记\\项目资料\\图片\\京北方云测试平台\\监控中心.png");
File file = new File("F:\\软件\\GamingCenter_1.2.3.4_Mechrevo.zip");
// 返回文件的唯一ID此ID用于文件下载、查询等功能
String fileId = NKFilesClient.uploadFile(ipAddress, port, file);
if (fileId != null)
{
System.out.println("文件上传成功文件ID" + fileId);
}
```
### 下载文件
WEB页面的形式
编辑一个html页面代码如下
```html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>测试文件下载功能</title>
</head>
<body>
<img src="http://192.168.0.40:9631/download/67527fdee523449488120ec2174cc589">
<br>
<br>
<br>
<a href="http://192.168.0.40:9631/download/1eae0044ffd54cdd8fbe844d8b6db46d" target="_blank">下载文件</a>
</body>
</html>
```
JAVA编码的形式
引用Maven依赖
```xml
<dependency>
<groupId>net.northking.commons</groupId>
<artifactId>nk-files-client</artifactId>
<version>2.0.0-SNAPSHOT</version>
</dependency>
```
JAVA示例代码如下:
```java
public void downloadFile01() throws IOException
{
String ipAddress = "192.168.0.40";
int port = 8512;
// 文件唯一ID
String fileId = "07d6d3736ea444069ada1452e7e4a167";
// 本地目录,用于存放下载下来的文件目录
String localPath = "D:\\TEST\\NKFilesClient";
// 下载成功后得到的本地文件对象
File localFile = NKFilesClient.downloadFile(ipAddress, port, fileId, localPath);
if (localFile != null)
{
System.out.println("文件下载成功,位置:" + localFile.getAbsoluteFile());
}
}
public void downloadFile02() throws IOException
{
String ipAddress = "192.168.0.40";
int port = 8512;
// 文件唯一ID
String fileId = "07d6d3736ea444069ada1452e7e4a167";
// 指定存放到本地文件系统具体的文件名称
String filePath = "D:\\TEST\\NKFilesClient\\" + UUID.randomUUID().toString() + ".nkf";
File localFile = new File(filePath);
NKFilesClient.downloadFile(ipAddress, port, fileId, localFile);
if (localFile != null)
{
System.out.println("文件下载成功,位置:" + localFile.getAbsoluteFile());
}
}
public void downloadFile03() throws IOException
{
String url = "http://111.203.253.33:9631/download/07d6d3736ea444069ada1452e7e4a167";
String localPath = "D:\\TEST\\NKFilesClient";
File localFile = NKFilesClient.downloadFile(url, localPath);
if (localFile != null)
{
System.out.println("文件下载成功,位置:" + localFile.getAbsoluteFile());
}
}
```