File
Provide manipulate functions on file: file download & file upload in the kintone app.
Constructor
Parameter
Name | Type | Required | Description |
---|---|---|---|
connection | Connection | yes | The connection module of this SDK. |
Sample code
Initial file class
Source codeFile fileManagement = new File(connection);
Methods
upload(filePath)
Upload file kintone via Rest API
Parameter
Name | Type | Required | Description |
---|---|---|---|
filePath | String | yes | The full path of file on your environment |
Return
Sample code
Get app sample
Source codeString username = "cybozu"; String password = "cybozu"; // Init authenticationAuth Auth kintoneAuth = new Auth(); kintoneAuth.setPasswordAuth(username, password); // Init Connection String myDomainName = "sample.cybozu.com"; Connection kintoneOnDemoDomain = new Connection(myDomainName, kintoneAuth); // Init File Module File kintoneFileManager = new File(kintoneOnDemoDomain); // execute upload file API String uploadPath = "C:/Users/Administrator/Desktop/upload"; FileModel fileModel = kintoneFileManager .upload(uploadPath + "test.txt");
download(fileKey, outPutFilePath)
Download file kintone via Rest API
Parameter
Name | Type | Required | Description |
---|---|---|---|
fileKey | String | yes | The file key of the uploaded file on kintone |
outPutFilePath | String | yes | The full path of output file on your environment |
Return
(none)
Sample code
Get apps sample
Source codeString username = "cybozu"; String password = "cybozu"; // Init authenticationAuth Auth kintoneAuth = new Auth(); kintoneAuth.setPasswordAuth(username, password); String myDomainName = "sample.cybozu.com"; Connection kintoneOnDemoDomain = new Connection(myDomainName, kintoneAuth); // Init File Module File kintoneFileManager = new File(kintoneOnDemoDomain); // Init Record Module Record kintonRecordManager = new Record(kintoneOnDemoDomain); // get filekey Integer appID = 1; Integer recordID =1; GetRecordResponse recordJson = kintonRecordManager.getRecord(appID, recordID); HashMaprecordVal = recordJson.getRecord(); FieldValue fileVal = recordVal.get("TempFile"); ArrayList fileList = (ArrayList ) fileVal.getValue(); // execute download file API String downloadPath = "C:/Users/Administrator/Desktop/"; for (int i = 0; i < fileList.size(); i++) { FileModel fdata = fileList.get(i); kintoneFileManager.download(fdata.getFileKey(), downloadPath + fdata.getName()); }