Get data with AngularJS controller

I’m trying to get my data with an AngularJS controller but till now no response. My controller is working, only the get request gives problems. Do I also need to configure CORS?

This is my http get request:

$http.get("http://localhost:8100/nfs/file/app/standen/871687800000129355.txt",
               {headers: {'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImJGSFBQRjlLck0vZWREUE1LUS9qa0t3NytqZVhCb3ZYTStzdmlDRHp1MDg9IiwiaWF0IjoxNDc2MjE4NDc0fQ.qSqbew7hkjsWM16XWPNV00IUl_WpR2dlabhw9z9CwJQ'}}
               ).then(function(response) {
        
            scope.mysafe = response.data;
            });

Hello @Yerontour,

and welcome to the developer forum!

I see a couple of things:

  1. you are requesting a file: have you been writing the file with the same app (authtoken)? Currently all data is per default sandboxed per app by the launcher, which means that you can’t access the same file from different apps unless they are explicitly shared.
  2. you need to escape the paths inside the URL as the documentation states (we should probably provide examples for this). You can use the default Javascript feature encodeURIComponent to do that for each part. In your case the URL therefore must be: http://localhost:8100/nfs/file/app/standen%2F871687800000129355.txt"
  3. are you receiving any error message either on the console or somewhere else? Could you maybe add a .catch(console.error.bind(console)) at the end of your promise in order to see the error given by the request?
  4. CORS depends on the source of your Angular file. If it is hosted on localhost than this should usually be fine. If it wasn’t you should see a big red error in your developer console.

Staying tuned

2 Likes

hmmm…made the same mistake 2 days ago, create the an app/file via the API and tried to access it via drive with my Angular site.

Strange thing is that if I now want to upload a file with the same name to drive, I get this error: Operation Failed: NfsError::FileAlreadyExistWithSameName

1 Like

Thanx @ben, my first Angular app on safenetwork is live :slight_smile:

2 Likes

:tada: congrats!

Is it public? Do you want to share your link to it? And/or maybe share a link to the source code, so others could learn from it, too?

1 Like

Here is my source code: https://github.com/Yerontour/SafeNetworkDemo , I made a README file with some descriptions.

I start programming this year so I know all beginnings are hard, but with this AngularJS demo people with a little HTML and Javascript experience have an easy start.

1 Like

Awesome. Appreciate it!

You started this year? And decided to start with SAFE? That’s awesome – both things actually.

2 Likes

On my github account you can also find an Ethereum implementation, but I came to the conclusion that I need a platform with more functionality and throughput. I’m working on a Energy solution with a lot of transactions and for that Ethereum is to expensive in gas costs.

The future will be decentralized… :slight_smile:

4 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.