# Storage write issue

**URL:** https://forums.fusetools.com/t/storage-write-issue/2070
**Category:** How-to Discussions
**Created:** [February 11, 2016, 8:12pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070 "2016-02-11T20:12:58Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![wouter](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/wouter/32/168_2.png) [@wouter](https://forums.fusetools.com/u/wouter)
#### Post date: [February 11, 2016, 8:12pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070/1 "2016-02-11T20:12:58Z")

</div>

I am using Fuse to develop a new version of my app ‘contractnotify’. The UI is ready and i am now hooking up our API. Everything is working so far. I login making a POST request. I get a token back. This all works fine. Problem is when i try to write the token (or anything else) to a file called filedb.txt nothing happends. I am working on a mac so i first thought it had to do with file permissions, but i put everything on read/write and still no luck. Maybe my code is wrong, please advise. Thank you!

My code:

```auto
var Observable = require("FuseJS/Observable");var requestObject = {'username':'myusername', 'password':'mypassword'};

fetch('https://www.contractnotify.com/api/login&#39;, {
    method: 'POST',
    headers: { "Content-type": "application/json"},
    dataType: 'json',
    body: JSON.stringify(requestObject)
}).then(function(response) {
    status = response.status; // Get the HTTP status code
    response_ok = response.ok; // Is response.status in the 200-range?
    return response.json(); // This returns a promise
}).then(function(responseObject) {
    // Do something with the result
    console.log("Success"); //this works i get a success
    var thetoken = responseObject.token; // this is the token i get
    console.log(thetoken); //this shows the token and works
    var storage = require('FuseJS/Storage'); //require storage
    storage.write("/filedb.txt", thetoken); //write to file

}).catch(function(err) {
    // An error occured parsing Json
    console.log("error", status);
});

```

---

<div class="post-metadata">

### Author: ![COCPORN](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/cocporn/32/576_2.png) [@COCPORN](https://forums.fusetools.com/u/COCPORN)
#### Post date: [February 12, 2016, 7:06am UTC](https://forums.fusetools.com/t/storage-write-issue/2070/2 "2016-02-12T07:06:18Z")

</div>

Not 100% sure what the problem is, but:

```auto
storage.write("filedb.txt", thetoken).then(function (success)
{
    if (success) {
        console.log ('Stored file');
    } else {
        console.log ('Storing file FAILED');
    }
})

```

This will give you an indication of whether the operation failed or succeeded.

I would try removing the leading slash **/** from the filename, I think that could easily be the problem. Fuse currently stores files at the strangest locations on Windows by default, and it wouldn’t surprise me if trying to force an absolute path on Mac would cause it to fail.

---

<div class="post-metadata">

### Author: ![wouter](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/wouter/32/168_2.png) [@wouter](https://forums.fusetools.com/u/wouter)
#### Post date: [February 17, 2016, 12:01am UTC](https://forums.fusetools.com/t/storage-write-issue/2070/3 "2016-02-17T00:01:54Z")

</div>

Thank you for your reply. You understood correctly. Strange enough LOG result is ‘Stored file’, but there is nothing written to the file. I searched for filedb.txt on my mac (to check it was maybe stored somewhere else) but there is only the one i added and it’s empty. Any additional ideas? Thanks again!

---

<div class="post-metadata">

### Author: ![Kristian\_Hasselknipp](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/kristian_hasselknipp/32/549_2.png) [@Kristian\_Hasselknipp](https://forums.fusetools.com/u/Kristian_Hasselknipp)
#### Post date: [February 17, 2016, 2:34am UTC](https://forums.fusetools.com/t/storage-write-issue/2070/4 "2016-02-17T02:34:34Z")

</div>

what do you get in your log?

---

<div class="post-metadata">

### Author: ![wouter](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/wouter/32/168_2.png) [@wouter](https://forums.fusetools.com/u/wouter)
#### Post date: [February 17, 2016, 8:49pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070/5 "2016-02-17T20:49:31Z")

</div>

When i add this code i get ‘Stored file’. So fuse things it’s written, but file is empty.

---

<div class="post-metadata">

### Author: ![ck3k](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@ck3k](https://forums.fusetools.com/u/ck3k)
#### Post date: [March 4, 2016, 10:53pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070/6 "2016-03-04T22:53:28Z")

</div>

Any update to this? I have the same problem.

---

<div class="post-metadata">

### Author: ![Jake\_Taylor](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/jake_taylor/32/512_2.png) [@Jake\_Taylor](https://forums.fusetools.com/u/Jake_Taylor)
#### Post date: [March 4, 2016, 11:32pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070/7 "2016-03-04T23:32:33Z")

</div>

I’m currently making a ticket for this internally so we can get more eyes on it.

---

<div class="post-metadata">

### Author: ![ck3k](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@ck3k](https://forums.fusetools.com/u/ck3k)
#### Post date: [March 6, 2016, 1:07am UTC](https://forums.fusetools.com/t/storage-write-issue/2070/8 "2016-03-06T01:07:44Z")

</div>

Thanks @Jake, looking forward for an update.

---

<div class="post-metadata">

### Author: ![Bjorn-Olav\_Strand](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/bjorn-olav_strand/32/583_2.png) [@Bjorn-Olav\_Strand](https://forums.fusetools.com/u/Bjorn-Olav_Strand)
#### Post date: [March 6, 2016, 12:25pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070/9 "2016-03-06T12:25:34Z")

</div>

@wouter I suspect two issues in your code.

1. Leading slash. This will try to create `/filedb.txt`, and hopefully you don’t have access to that with the user you are running fuse under.

2. Unknown type of `thetoken`, the Storage API only works with strings.

Solution:

`storage.write("filedb.txt", "" + thetoken); //write to file`

@ck3k:

Can you post a complete test-case that demonstrates the problem? This code works for me:

```auto
<App Theme="Basic">
    <JavaScript>
      var requestObject = {'username':'myusername', 'password':'mypassword'};
      var storage = require('FuseJS/Storage'); //require storage
      storage.write("filedb.txt", JSON.stringify(requestObject)); //write to file
     </JavaScript>
</App>

```

And the file is in `~/.local/share/filedb.txt`

```auto
$ cat ~/.local/share/filedb.txt
{"username":"myusername","password":"mypassword"}

```

---

<div class="post-metadata">

### Author: ![ck3k](https://avatars.discourse-cdn.com/v4/letter/c/9d8465/32.png) [@ck3k](https://forums.fusetools.com/u/ck3k)
#### Post date: [March 7, 2016, 2:08pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070/10 "2016-03-07T14:08:53Z")

</div>

Hey @Bjorn. Thank you for your reply. It was up to me I guess. I thought the file will be saved in project directory and I haven’t seen any details of the saved file location on API page. I’ve just cheked and the file is there and it’s written properly.

One note, the same directory for Windows is located @ %AppData%\Local.

Thanks for the help, appreciated!

---

<div class="post-metadata">

### Author: ![wouter](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/wouter/32/168_2.png) [@wouter](https://forums.fusetools.com/u/wouter)
#### Post date: [March 8, 2016, 11:11am UTC](https://forums.fusetools.com/t/storage-write-issue/2070/11 "2016-03-08T11:11:05Z")

</div>

Hey @Bjorn, thank you for your time. I will look into it tonight!

---

<div class="post-metadata">

### Author: ![wouter](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/wouter/32/168_2.png) [@wouter](https://forums.fusetools.com/u/wouter)
#### Post date: [March 13, 2016, 6:47pm UTC](https://forums.fusetools.com/t/storage-write-issue/2070/12 "2016-03-13T18:47:39Z")

</div>

`This worked for me: storage.write("filedb.txt", "" + thetoken);`

i thought the the filedb.txt would be in the folder. But it was stored like Bjorn mentioned, which was a bit difficult to find.

When i now read filedb.txt with the following code, i will get my saved token:

`Storage.write("filedb.txt", "" + thetoken).then(function(wasSuccess) { if(wasSuccess) { Storage.read("filedb.txt").then(function(content) { storedToken = content; console.log('storing token success, token = ' + storedToken); }); } });`

Thank you!
