Upload file using javascript api

Is there a way to do this using javascript api?


Hello Vern

As of now, unfortunately, you will need to use FormData objects and/or BLOB for the file attachments (unless it’s a UTF-8 text file).
It will be pretty difficult doing so with the kintone.api() or the kintone.proxy() so XMLHttpRequest is like an only choice.

I don’t know this will help, but the following is an example of doing so using XMLHttpRequest:

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
} else {
// error