Baby Dev Questions

@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

@hunterlester ^^ ?

Blah!

2 Likes

Hi Joseph,

Please excuse the delayed reply.

Thank you for raising this issue.

It appears that we don’t have that convenient functionality, unless the following functions are able to operate on whole directories and not just single files:

http://docs.maidsafe.net/beaker-plugin-safe-app/#windowsafenfsinsert
http://docs.maidsafe.net/beaker-plugin-safe-app/#windowsafenfsfetch

I’m going to experiment with the code, ask our team, and come back with either a concrete code example or an explanation.

I’m starting my search for answers here: https://github.com/maidsafe/safe_examples/blob/dev/web_hosting_manager/app/lib/tasks.js#L45

It appears that we should be able to get the container to which the file or directory belong, and then fetch the directory using the path as the key.

That’s where I’m starting, I’ll get back to you with more.

4 Likes

Hey @hunterlester any news? :slight_smile:

EDIT: Or @bochaco? See above

2 Likes

Hi Joseph,

I’ve been running NFS tests to clarify how everything works.

This is a quick note to let you know that I will post a detailed technical response tomorrow. The delay is my own fault and I’m thinking about a system to stay on top of these support questions that I take responsibility for, especially when days are particularly busy.

In summary, all files for a particular service are stored as entries in a MutableData structure. If a file belongs to a directory, it’s specified in the entry’s key.

Example mutable data entries:
Format: <key>:<value>

"index.html": <hashed file meta data>
"favicon.ico": <hashed file meta data>
"js/scripts.js": <hashed file meta data>
"js/deps.js": <hashed file meta data>
"js/dependencies/jquery.min.js": <hashed file meta data>
"css/styles.css": <hashed file meta data>
"css/bootstrap.min.css": <hashed file meta data>
"css/fonts/font.ttf": <hashed file meta data>

I was converting keys to string values and then using regular expressions to just retrieve those values whose keys begin with the desired directory.

Does this make sense?

More tomorrow…

4 Likes

Follow-up from yesterday.

Looking at your original post, you are asking if there exist convenient functions for creating a service, creating a public ID, and for getting a directory, like the old DNS and NFS api functions.

They don’t exist in the new api’s although the web hosting manager application is meant to provide that higher level convenience.

I was going to write out a long post about how I technically perform all of these operations, which I can still do if you like, however, I happen to be making a video that walks through all of these operations and explains SAFE DNS conventions.

I hope to get the video approved and released this Thursday with the dev update.

8 Likes

Both sound excellent, but I think the blog post is primary: more easily used and referred to, while the video helps those who find it hard to follow on its own or to get started quickly.

Ideally though I think we’ll need a helper library if these functions are not part of the API. Can you check if there are any plans for that, because if not it makes sense for the community to jump in.

Thanks Hunter, this is very helpful

5 Likes