winform读取服务器文件夹信息,C#开发BIMFACE系列7 服务端API之获取文件信息列表

本文详细介绍如何获取BIMFACE平台中所有上传过的文件信息列表。

请求地址:GET https://file.bimface.com/files

说明:根据多种查询条件获取文件详细信息列表,支持分页

参数:

c8d097e753abdae62e1885acddb03610.png

请求 path(示例):https://file.bimface.com/files

请求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"

HTTP响应示例(200):

{

"code" : "success",

"data" : [ {

"createTime" : "2017-11-09 13:25:03",

"etag" : "19349858cjs98ericu989",

"fileId" : 1216113551663296,

"length" : 39044,

"name" : "-1F.rvt",

"status" : "success",

"suffix" : "rvt"

} ],

"message" : ""

}

注意上面返回的data内容是一个数组。

C#实现方法:

1 ///

2 /// 根据多种查询条件获取文件详细信息列表,支持分页

3 ///

4 /// 令牌

5 /// 起始日期,格式为 yyyy-MM-dd。默认为空,查询所有

6 /// 截止日期,格式为 yyyy-MM-dd。默认为空,查询所有

7 /// 查询结果数, 默认为100, 最大500。默认100

8 /// 查询结果偏移,从查询结果的第offset条开始返回数据。默认-1,查询所有

9 /// 文件状态,uploading,success,failure。默认为空,查询所有

10 /// 文件后缀。默认为空,查询所有

11 ///

12 public virtual FileInfoListGetResponse GetFileInfoList(string accessToken, string startTime = "", string endTime = "", long rows = 100, long offset = -1, string status = "", string suffix = "")

13 {

14 FileInfoListGetResponse response = new FileInfoListGetResponse();

15

16 #region 校验

17 if (rows < 0 || rows > 500)

18 {

19 response.Message = "参数[rows]超出范围。要求控制在1到500之间!";

20

21 return response;

22 }

23

24 #endregion

25

26 //GET https://file.bimface.com/files

27 string url = BimfaceConstants.FILE_HOST + "/files";

28 url = url + "?rows=" + rows;

29 if (!string.IsNullOrWhiteSpace(startTime))

30 {

31 url = url + "?rows=" + rows;

32 }

33 if (!string.IsNullOrWhiteSpace(endTime))

34 {

35 url = url + "?endTime=" + endTime;

36 }

37 if (offset >= 0)

38 {

39 url = url + "?offset=" + offset;

40 }

41 if (!string.IsNullOrWhiteSpace(status))

42 {

43 url = url + "?status=" + status;

44 }

45 if (!string.IsNullOrWhiteSpace(suffix))

46 {

47 url = url + "?suffix=" + suffix;

48 }

49

50 BimFaceHttpHeaders headers = new BimFaceHttpHeaders();

51 headers.AddOAuth2Header(accessToken);

52

53 try

54 {

55 HttpManager httpManager = new HttpManager(headers);

56 HttpResult httpResult =httpManager.Get(url);

57 if (httpResult.Status == HttpResult.STATUS_SUCCESS)

58 {

59 response = httpResult.Text.DeserializeJsonToObject();

60 }

61 else

62 {

63 response = new FileInfoListGetResponse

64 {

65 Message = httpResult.RefText

66 };

67 }

68

69 return response;

70 }

71 catch (Exception ex)

72 {

73 throw new Exception("[获取文件信息列表]发生异常!", ex);

74 }

75 }

测试

在BIMFACE的控制台中可以看到我们上传的文件列表,共计2个文件。

34d332e113c5df1c4bc77b2aa20f41bb.png

下面通过调用上述的GetFileInfoList()方法来测试,结果如下,与后台的文件列表一致。

5a20bd5c8b75dd457088258546f60a7f.png

测试程序如下:

// 获取文件信息列表

protected void btnGetFileList_Click(object sender, EventArgs e)

{

txtFileInfo.Text = string.Empty;

string token = txtAccessToken.Text;

FileApi api = new FileApi();

FileInfoListGetResponse response = api.GetFileInfoList(token);

List fileInfoList = response.Data;

StringBuilder sbFiles = new StringBuilder();

foreach(FileInfoGetEntity fileInfo in fileInfoList)

{

sbFiles.AppendLine("名称:" + fileInfo.ToString());

}

txtFileInfo.Text = response.Code

+ Environment.NewLine

+ response.Message

+ Environment.NewLine

+ "共获取 " + fileInfoList.Count + " 个文件。"

+ Environment.NewLine

+ sbFiles;

}

·

·

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值