Hi does anyone know the API for uploading files / folders to SAFE?
we were having trouble finding documentation for that
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
I want to create new stuctured data object. I first create a new safe account and then Ill execute the next steps:
http://localhost:8100/auth (POST), with these credentials:
{
âappâ: {
ânameâ: âYerontourAppâ,
âidâ: âyerontour-appâ,
âversionâ: â0.0.1â,
âvendorâ: âYerontourâ
},
âpermissionsâ: [âLOW_LEVEL_APIâ]
}
http://localhost:8100/structured-data (POST), with the credentials in the API documentation and get this result:
{
âhandleIdâ: 1
}
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.
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?
@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.
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
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.
Wow is that really true?
YesâŚwas thinking about 32 bit IP addresses, but its bytes. I have a network protocol background.
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
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.
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
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