Upload File

Uploads a file to Kintone.

MethodPOST
URLhttps://{subdomain}.kintone.com/k/v1/file.json
Authentication Password Authentication, API Token Authentication, Session Authentication
Content-Typemultipart/form-data

When a file is uploaded, it produces a fileKey.
Note that although this API uploads a file to Kintone, it does not upload the file to an Attachment field of an App.
To upload the file to an Attachment field, the fileKey is used with the Add Record or Update Record API.

Contents

Permissions

No record related permissions are needed, as this API does not directly attach a file to an App.

Request Parameters

Request Format

The request is sent in a multipart/form-data format. For more information, refer to the following RFC documents:

Within the Content-Disposition header, specify file for the name parameter and the name of the file for the filename parameter.

HTTP Request Header

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
POST /k/v1/file.json HTTP/1.1
Host: example.kintone.com:443
X-Cybozu-API-Token: TOKEN
Content-Type: multipart/form-data; boundary="---------------------------bee48a285354"
Content-Length: 188
-----------------------------bee48a285354
Content-Disposition: form-data; name="file"; filename="sample.txt"
Content-Type: text/plain

test
-----------------------------bee48a285354--

Sample Request

JavaScript

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
var blob = new Blob(['Sample Test File'], {type: 'text/plain'});
var formData = new FormData();
formData.append('__REQUEST_TOKEN__', kintone.getRequestToken());
formData.append('file', blob, 'test.txt');

var url = 'https://{subdomain}.kintone.com/k/v1/file.json';
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onload = function() {
  if (xhr.status === 200) {
    // success
    console.log(JSON.parse(xhr.responseText));
  } else {
    // error
    console.log(JSON.parse(xhr.responseText));
  }
};
xhr.send(formData);

curl Sample

1
2
3
curl -X POST 'https://{subdomain}.kintone.com/k/v1/file.json' \
  -H 'X-Cybozu-API-Token: L08xCvTh7A1EVm3rZimF98R8VLP3k4lMlzELqyCx' \
  -F 'file=@FILEPATH'

Fetch API Sample

For more information on Fetch API, refer to the following link:
Fetch API (External link)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
const blob = new Blob(['Sample Test File'], {
  type: 'text/plain',
});
const formData = new FormData();
// CSRF TOKEN: used for all APIs with HTTP methods of POST, PUT, and DELETE on Kintone.
formData.append('__REQUEST_TOKEN__', kintone.getRequestToken());
formData.append('file', blob, 'test.txt');

const headers = {
  'X-Requested-With': 'XMLHttpRequest',
};
const resp = await fetch('/k/v1/file.json', {
  method: 'POST',
  headers,
  body: formData,
});
const respData = await resp.json();
console.log(respData);

Response Parameters

Parameter Type Description
fileKey String The fileKey representing an uploaded file. Use this fileKey with the following APIs to attach it to an Attachment field of an app:
Add Record
Add Records
Update Record
Update Records
For more information, refer to the following article:
Field Types

Sample Response

1
2
3
{
  "fileKey": " c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6"
}

fileKeys

There are two types of fileKeys used in Kintone REST APIs.

  • Upload File API filekey
    • e.g. c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6
    • This fileKey is used to update a record with an Attachment field, or add a record with an attachment.
    • This article discusses this type of fileKey
  • Get Record API filekey
    • e.g. 201202061155587E339F9067544F1A92C743460E3D12B3297
    • This fileKey is used when downloading a file from an Attachment field.
    • This article does not cover this type of fileKey.

Attaching the File to an Attachment Field

Use the following APIs, and set the value of the fileKey as the fileKey obtained from the Upload File API, as shown in the example body below.
Add Record
Add Records
Update Record
Update Records

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "app": 3,
  "id": 6,
  "record": {
    "attached_file": {
      "value": [
        {
          "fileKey": " c15b3870-7505-4ab6-9d8d-b9bdbc74f5d6"
        }
      ]
    }
  }
}

Limitations

  • Only 1 file can be uploaded at a time.
  • After the file is uploaded onto Kintone, the file will be deleted after 3 days if the Add Record or Update Record API is not used.
  • This API cannot be called with the following API:
    Kintone REST API Request API
  • Files stored in the temporary storage area are also included in the disk usage.
  • File keys obtained through the API for retrieving records cannot be used for file uploads.
  • For other limitations, refer to the following article:
    Kintone REST API Limitations