Download File

Downloads files from an attachment field in an app.

MethodGET
URLhttps://{subdomain}.kintone.com/k/v1/file.json
Authentication Password Authentication, API Token Authentication, Session Authentication
Content-Typeapplication/json (not needed if specifying the query with a query string)

Contents

Permissions

  • App view permissions for the related App are needed.
  • Record view permissions for the related record are needed.
  • Field view permissions for the related field are needed.

Request Parameters

The file is downloaded by sending the fileKey of the attachment file. This fileKey though will first need to be obtained using the Get Record API.

Note that this fileKey is different from the fileKey obtained from the response when using the Upload File API.

PARAMETER VALUE REQUIRED DESCRIPTION
fileKey String Yes The value that is set on the Attachment field in the response data returned when using the Get Record API.

Sample Request (Query String)

JavaScript

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
var fileKey = kintone.app.record.get().record.file.value[0].fileKey;
var url = 'https://{subdomain}.kintone.com/k/v1/file.json?fileKey=' + fileKey;
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.responseType = 'blob';
xhr.onload = function() {
  if (xhr.status === 200) {
    // success
    var blob = new Blob([xhr.response]);
    var windowUrl = window.URL || window.webkitURL;
    var blobUrl = windowUrl.createObjectURL(blob);
    console.log(blobUrl);
  } else {
    // error
    console.log(xhr.responseText);
  }
};
xhr.send();

curl Sample

Use the -o option to save the output into a file.

1
2
3
curl -X GET 'https://{subdomain}.kintone.com/k/v1/file.json?fileKey=20150417022053715283FF97DC413CBC4B7A41C' \
  -H 'X-Cybozu-API-Token: L08xCvTh7A1EVm3rZimF98R8VLP3k4lMlzELqyCx'
  -o ./sample.txt

Sample Request (JSON)

JavaScript

N/A.
Data cannot be set in the body for GET methods when using XMLHttpRequest (XHR) (External link) .

curl Sample

1
2
3
4
5
6
curl -X GET 'https://{subdomain}.kintone.com/k/v1/file.json' \
  -H 'X-Cybozu-API-Token: L08xCvTh7A1EVm3rZimF98R8VLP3k4lMlzELqyCx' \
  -H 'Content-Type: application/json' \
  -d '{
    "fileKey": "20150417022053715283FF97DC413CBC4B7A41C"
  }'

Sample Response

The MIME media type of the uploaded file will be stated in the Content-Type, and information of the file will be set inside the response body.

Obtaining the fileKey

The fileKey of a file can be found in the response of the Get Record API.
Below is a sample response including the fileKey to be used with the Download File API.

 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
{
  "record": {
    "updated_time": {
      "type": "UPDATED_TIME",
      "value": "2017-03-15T11:59:06Z"
    },
    "file": {
      "type": "FILE",
      "value": [
        {
          "contentType": "text/plain",
          "fileKey": "20150417022053715283FF97DC413CBC4B7A41C",
          "name": "kintoneUpdates.txt",
          "size": "25302"
        },
        {
          "contentType": "text/plain",
          "fileKey": "20150417022159ECFC1223C4B34C939E1B9BD25",
          "name": "APIUpdatestxt",
          "size": "20311"
        }
      ]
    }
  }
}

Limitations

This API cannot be called with the Kintone API Request API.