本文詳細介紹如何獲取BIMFACE平臺中全部上傳過的文件信息列表。html
請求地址:GET https://file.bimface.com/files
json
說明:根據多種查詢條件獲取文件詳細信息列表,支持分頁api
參數:
數組
請求 path(示例):https://file.bimface.com/files測試
請求 header(示例):"Authorization: Bearer dc671840-bacc-4dc5-a134-97c1918d664b"
ui
HTTP響應示例(200):url
{ "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內容是一個數組。spa
C#實現方法:code
1 /// <summary> 2 /// 根據多種查詢條件獲取文件詳細信息列表,支持分頁 3 /// </summary> 4 /// <param name="accessToken">令牌</param> 5 /// <param name="startTime">起始日期,格式爲 yyyy-MM-dd。默認爲空,查詢全部</param> 6 /// <param name="endTime">截止日期,格式爲 yyyy-MM-dd。默認爲空,查詢全部</param> 7 /// <param name="rows">查詢結果數, 默認爲100, 最大500。默認100</param> 8 /// <param name="offset">查詢結果偏移,從查詢結果的第offset條開始返回數據。默認-1,查詢全部</param> 9 /// <param name="status">文件狀態,uploading,success,failure。默認爲空,查詢全部</param> 10 /// <param name="suffix">文件後綴。默認爲空,查詢全部</param> 11 /// <returns></returns> 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<FileInfoListGetResponse>(); 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 }
其中引用的 httpManager.Get() 方法,請參考《C#開發BIMFACE系列6 服務端API之獲取文件信息》,方法徹底同樣。
在BIMFACE的控制檯中能夠看到咱們上傳的文件列表,共計2個文件。htm
下面經過調用上述的GetFileInfoList()方法來測試,結果以下,與後臺的文件列表一致。
測試程序以下:
// 獲取文件信息列表 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<FileInfoGetEntity> 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; }