# How to create a new file and save it with ArrayBuffer content?

**URL:** <https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [July 19, 2017, 2:33am UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628 "2017-07-19T02:33:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![s333](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@s333](https://discourse.threejs.org/u/s333)\
**Post date:** [July 19, 2017, 2:33am UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/1 "2017-07-19T02:33:38Z")

</div>

I have an arraybuffer which i want to save into a new file so i can use them later for other things.

how can i store the ArrayBuffer in a txt file and choose the location to save it?

---

<div class="post-metadata">

**Author:** ![looeee](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/looeee/32/59_2.png) [@looeee](https://discourse.threejs.org/u/looeee)\
**Post date:** [July 19, 2017, 2:52am UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/2 "2017-07-19T02:52:37Z")

</div>

You can’t save files with JavaScript directly as it doesn’t have access to the file system from within the browser - you’ll have to use a server side language such as PHP if you want to save the file in the traditional sense (i.e. to a directory on your computer).  
Alternatively have a look at [Web Storage](https://www.w3schools.com/html/html5_webstorage.asp) and see if that would suit your needs.

Although if you want a popup box that asks the user where they want to save the file, that _is_ possible.

```auto
const link = document.createElement( 'a' );
link.style.display = 'none';
document.body.appendChild( link );

const blob = new Blob( [yourArray], { type: 'text/plain' } );	
const objectURL = URL.createObjectURL( blob );
 
link.href = objectURL;
link.href = URL.createObjectURL( blob );
link.download = 'data.json';
link.click();
 

```

---

<div class="post-metadata">

**Author:** ![s333](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@s333](https://discourse.threejs.org/u/s333)\
**Post date:** [July 19, 2017, 4:20am UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/3 "2017-07-19T04:20:50Z")

</div>

i tried this but it partially worked for me. is there another wa other than  
blob. my content is an ArrayBuffer. so i want to save it like this in the  
file too.

blob aparently changes the formatting slightly.

---

<div class="post-metadata">

**Author:** ![looeee](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/looeee/32/59_2.png) [@looeee](https://discourse.threejs.org/u/looeee)\
**Post date:** [July 19, 2017, 6:33am UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/4 "2017-07-19T06:33:03Z")

</div>

Try changing the Blob’s type from ‘text/plain’ - I think for an ArrayBuffer it should be '‘application/octet-binary’.

---

<div class="post-metadata">

**Author:** ![s333](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@s333](https://discourse.threejs.org/u/s333)\
**Post date:** [July 19, 2017, 7:48pm UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/5 "2017-07-19T19:48:01Z")

</div>

```
var file = new Blob([response], {type: "application/octet-binary;charset=utf-8"});
		var a = document.createElement("a"), url = URL.createObjectURL(file);
        a.href = url;
        a.download = filename;
		document.body.appendChild(a);
		a.click();

```

this didnt work either. it is still complaining about the format.

---

<div class="post-metadata">

**Author:** ![looeee](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/looeee/32/59_2.png) [@looeee](https://discourse.threejs.org/u/looeee)\
**Post date:** [July 20, 2017, 12:34am UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/6 "2017-07-20T00:34:52Z")

</div>

Can you post more of your code? It’s hard to know what’s going on without it.

---

<div class="post-metadata">

**Author:** ![1113](https://avatars.discourse-cdn.com/v4/letter/1/c89c15/32.png) [@1113](https://discourse.threejs.org/u/1113)\
**Post date:** [May 30, 2018, 10:04am UTC](https://discourse.threejs.org/t/how-to-create-a-new-file-and-save-it-with-arraybuffer-content/628/7 "2018-05-30T10:04:06Z")

</div>

It work for me. The mimeType for binary is application/octet-stream
