Baby Dev Questions

Hi does anyone know the API for uploading files / folders to SAFE?

we were having trouble finding documentation for that

You can use the safeNfs methods to create directories and save files. The is no “upload directory” function in the API, so you would write this yourself. Or you could look at the code in the demo app and try copying parts of that.

Creating a library of useful functions like this would also be useful - kind of extending the API :slight_smile:

2 Likes

I want to create new stuctured data object. I first create a new safe account and then Ill execute the next steps:

  1. http://localhost:8100/auth (POST), with these credentials:
    {
    “app”: {
    “name”: “YerontourApp”,
    “id”: “yerontour-app”,
    “version”: “0.0.1”,
    “vendor”: “Yerontour”
    },
    “permissions”: [“LOW_LEVEL_API”]
    }

  2. http://localhost:8100/structured-data (POST), with the credentials in the API documentation and get this result:
    {
    “handleId”: 1
    }

  3. http://localhost:8100/structured-data/1 (PUT), with the result:
    {
    “errorCode”: -23,
    “description”: “CoreError::MutationFailure::MutationError::DataExists”
    }

Good thing is that my structured data is created, but I don’t understand the error message.

1 Like

looks like step 2 got the job done and step 3 was redundant so it was notifying you of that

@happybeing one last question while I got ya here:

does safe-js really cover pretty much every API command released by MaidSafe so far?

I thought it only did the basic things like files / folders but now I’m seeing it handles the LOW_LEVEL_API stuff too like structured data etc?

is that right?

So then it’s a bug in the api documentation? :slight_smile:

hmm could be, i’ve found a few (mostly typos tho) and if you catch any then message @frabrunelle

@frabrunelle , can you explain the ‘save structured data’ and ‘save appendable data’ api call? With the create api call the structured/appendable data is created and saved.

1 Like

I think you are trying to create an SD with a name that’s already assigned to an existing SD (perhaps created by you the first time you ran that same code). Try changing the name of the SD in step 2.

So I guess the SD you are seeing created is the one you created the very first time.

It means that a structured data already exists at that address. Try giving it another name :slight_smile:

Thanx, this works…I thought that the name was unique within the app. Is 32 bytes sufficient to guarantee uniqueness?

With 32 bytes you have more than1,15E+77 possibilities. Only to compare, the atoms in our solar system is about 1,2E+54 so you have about 100.000.000.000.000.000.000.000 solar system’s atoms to play.

Yes, I think is sufficient.

2 Likes

Wow is that really true?

Yes…was thinking about 32 bit IP addresses, but its bytes. I have a network protocol background. :smile:

1 Like

EDIT: partly solved, I switched to the safe-js library. With the library I see my app name instead of ‘Anonymous Application’.

I have an 401 error when requesting a file via my browsers (local env with google chrome and in beaker browser on safenetwork). API calls with ‘low level api’ doesn’t give this problem.

GET http://localhost:8100/nfs/file/app/company/websites/www/config.json 401 (Unauthorized)

I guess it’s a problem with ‘Anonymous Application’ when I use a browser, with Postman or NodeJS I see here my app name. The file is is a public folder and I do the request with an AngularJS controller. I also tried with the config file in the app root folder (private) with the same issue. This is my app authentication request:

{“app”:
{“name”:“my-test-application”,
“id”:“my-test-application”,
“version”:“0.0.1”,
“vendor”:“my-test-application”},
“permissions”:[“LOW_LEVEL_API”,“SAFE_DRIVE_ACCESS”]
}

Btw, when using http://api.safenet I get this error:
GET http://api.safenet/nfs/file/app/company/websites/www/config.json net::ERR_BLOCKED_BY_CLIENT

You need to encode the URL when you do that request, aka replace the / in the path:

GET /nfs/file/:rootPath/:filePath

As your rootPath is company and website/www/config.json is the path, the request should be: website%2Fwww%2Fconfig.json - you can easily generate those using the Javsacript function encodeURIComponent. So your full request would be:

GET /nfs/file/company/website%2Fwww%2Fconfig.json

4 Likes

question:
#uploading files with safe-js

does anyone know where to begin with this?

has been stumping us for a little while here,

maybe I’ve missed some documentation?

Have been having trouble finding anything about this, thanks!

You can use safeNfs to Create a file, then write the contents. That’s it, do it for each file you want to upload.

1 Like

just so I know, back to devv-ing now and just so I’m certain:

SafeEditor doesn’t work anymore, and there’s nothing else like it, correct?

There’s nothing that can let me edit my MS Demo App ‘/public/’ files right?

Does the new safe js DOM api have a method for creating and getting folders/directories like the old safe js

getDir

(https://api.safedev.org/nfs/directory/get-directory.html)

token - (string) auth token
dirPath - (string) file path
isPathShared - (bool - optional) true if writing to the sharedDRIVE, false writes to APP;
Returns a Promise which resolves to a JSON object of dir info.

{
“info”: {
“name”: “images”,
“isPrivate”: true,
“createdOn”: “2016-09-26T04:41:05.342Z”,
“modifiedOn”: “2016-09-26T04:41:05.342Z”,
“metadata”: “c2FtcGxlIG1ldGFkYXRh”
},
“files”: ,
“subDirectories”:
}

Is it possible to create a new public id and service name like the old safe js?
when looking into the web hosting manager i found the function

safe.auth.getAccessContainerInfo(accessContainers.publicNames)

which is used for public ids and services but i couldn’t find documentation for it in the DOM api or the Node Api

2 Likes