# Upload file using javascript api

**URL:** <https://forum.kintone.dev/t/upload-file-using-javascript-api/155>\
**Category:** General\
**Created:** [July 9, 2018, 1:03pm UTC](https://forum.kintone.dev/t/upload-file-using-javascript-api/155 "2018-07-09T13:03:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [July 9, 2018, 1:03pm UTC](https://forum.kintone.dev/t/upload-file-using-javascript-api/155/1 "2018-07-09T13:03:40Z")

</div>

Is there a way to do this using javascript api?

[https://developer.kintone.io/hc/en-us/articles/212494448/](https://developer.kintone.io/hc/en-us/articles/212494448/)

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [July 9, 2018, 2:42pm UTC](https://forum.kintone.dev/t/upload-file-using-javascript-api/155/2 "2018-07-09T14:42:39Z")

</div>

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
console.log(JSON.parse(xhr.responseText));
} else {
// error
console.log(JSON.parse(xhr.responseText));
}
};
xhr.send(formData);
```
