-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathFileExample.java
More file actions
37 lines (31 loc) · 1.08 KB
/
FileExample.java
File metadata and controls
37 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package example.file;
import com.coze.openapi.client.files.RetrieveFileReq;
import com.coze.openapi.client.files.UploadFileReq;
import com.coze.openapi.client.files.model.FileInfo;
import com.coze.openapi.service.auth.TokenAuth;
import com.coze.openapi.service.service.CozeAPI;
public class FileExample {
public static void main(String[] args) {
String token = System.getenv("COZE_API_TOKEN");
TokenAuth authCli = new TokenAuth(token);
CozeAPI coze =
new CozeAPI.Builder()
.baseURL(System.getenv("COZE_API_BASE"))
.auth(authCli)
.readTimeout(10000)
.build();
;
String filePath = System.getenv("FILE_PATH");
// *** 上传文件 ***//
FileInfo fileInfo = coze.files().upload(UploadFileReq.of(filePath)).getFileInfo();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// *** 获取文件 ***//
FileInfo retrievedInfo =
coze.files().retrieve(RetrieveFileReq.of(fileInfo.getID())).getFileInfo();
System.out.println(retrievedInfo);
}
}