How to upload a file to the network

@hunterlester could you also explain how to run the script in one go instead of running all the snippets one by one ?

running snipets is good to learn, but very time consuming to run

1 Like

I’ll include a complete code example.

What you’re uncovering is good. You’re uncovering that the end user is not receiving enough useful information, if any, if an operation is unsuccessful.

According to the steps above, you didn’t create an entries object for your bonnie service, but regardless, authenticator should have let you know.

5 Likes

the learning curve is a bit steep but your tool is fantastic.
I am a bit anxious for what comes next (let user insert dynamic content on my site must be tough ). But let’s proceed step by step. I have watched your vid countless times, started from scratch all over again with your write up, and couldn’t upload a site without webhosting manager yet :sob:

3 Likes

The learning curve is indeed steep, but wouldn’t it be boring otherwise? :smiley:

@hunterlester I have two questions regarding handle freeing:

1.) In my example app I get the error “Uncaught (in promise) TypeError: Cannot read property ‘then’ of undefined” when freeing the mdHandle. It seems that free() doesn’t return anything? The error is thrown at this point of code:

window.safeMutableData.free(mdHandle).then(_ => {
mdHandle = null;
});

2.) Why is it necessary to free these resources? I mean, what benefit does it have? Just for memory management of the library (e.g. browser) or is the network also affected (e.g. are the handles otherwise being kept stored on the network?)

1 Like

Hi, is it possible to use this API into Electron for exemple (how?) or do we have to use the safe browser for now?

Since the “window” object contains the safeApi… :smiley:

@SwissPrivateBanker I’ll get back as soon as I can. Instead of producing successes, I’m attempting all the ways in which the steps in this operation can go wrong.

@Mindphreaker Regarding first question, when did you clone the repos? I recently fixed that error you are receiving about the use of then. If you have the latest, I’ll take another look into what I missed.

For the second question, thank you to @bochaco for the explanation.
If I’m butchering this explanation, let it not reflect poorly on him.

In all cases, the allocated resources represented by a handle only have to do with local system heap and are not effecting network memory.

The good thing about the use of the SAFE browser is that even if calls are not made to free resources, those resources will be freed from system heap when the browser is closed and the JS garbage collector is triggered.

Same thing for use of safe_app_nodejs when making your own applications. Those resources will eventually be freed, when garbage collector is triggered.

I’m still learning our core Rust libraries, so I can’t speak very well to the low level but these libraries do have redundancies to ensure memory safety.

To your original question then, why do we then even need to manually free resources on the client?
When I’ve not freed resources, I’ve eventually run into generic errors and am no longer able to perform certain operations. So I think this is about managing the current client instance.

I’d like to replicate my errors and look more into this. Thank you for bringing it up.

@JesusTheHun Thank you for the question. You’re not stuck with the SAFE web API in the browser. You may use safe_app_nodejs API to allow applications, including electron applications, to interface with the network. See email app example

5 Likes

I’d just add that we are currently working on making sure that whenever a tab is closed the browser automatically frees all resources created by the contained app. As @hunterlester well explained, this is only a memory management thing on the browser, these handles only live in the browser’s main process.

6 Likes

Thanks for the clarification!

1 Like

@SwissPrivateBanker hey, good to see you going beyond your banker ways and getting into code :wink: but I’m curious how you got the playground to work - I haven’t tried that step because according to the OP (quoted above) you first need the dev-mode browser, but I can’t get that to build.

Did you build the dev-mode Browser, or did you not need to?

I’m planning to play tomorrow, so a solution to this would be great, or I’ll just wing it! :slight_smile:

3 Likes

replying to you in pm about this.

I have an idea about an app I have dreamt to build for years but can’t do on the clearnet.
Safe is the only way for me to see this through.
My interest in SAFE is not just speculative :wink:

2 Likes

@SwissPrivateBanker is on Windows so we were able to figure some things out together.

I badly need a way to efficiently test and build for other platforms.

Working on it. Thankfully we have @srini on the team now :grinning:

Good news coming.

My mess of a browser build may be replaced by a very clean and simple toggle.

5 Likes

Would be very handy if you could enter in the port to use

1 Like

@hunterlester . Thank you for the api playground. It really helps to understand how it works. I am new to the entire concept of Safenetwork hence bear with me if my questions are naive. When I am following the steps I get error at Step 7 when I am trying to upload using the API playground “Account not found for ClientManager(name: f06168…)” at the power shell and “fileHandle: Core error: Routing client error -> Account does not exist for client” on API playground.
I am using windows 10 and I have cloned and compiled the dev-browser and safe_dom_api_playground yesterday. Any pointers would be really helpful.

1 Like

Welcome to the community and ask away!

Is this occurring after committing the file with window.safeNfs.insert?

1 Like

Thank you for the welcome and quick response. I was using the playground so used the option safenfs - create. Chose the file and clicked run. At this point I got the message.

1 Like

In Step 7, When I use safe web API playground, the file explorer selects the file, but does not return the fileHandle.
on inspecting console logs on Safe Browser (safe_browser-v0.2.1-linux-x64-mock on Ubuntu 16.04.2 LTS), getting error.


When I have the fileContent with static html data, it works.
Is it related to the tag type ? I used 15002.
Could someone point me in right direction.
I am trying to upload an image.

2 Likes

@Saket @sadeesh.r Since created the original post, some things have changed in how mock routing works in addition to some other updates we are rolling out.

We are working on testing right now and will release updates soon to get you two back on track.

4 Likes

@hunterlester Thanks for the reply, we will wait for the updates.

Check out my website safedemo.jam it uses a function called blobtobuffer which will get rid of your error, I’ve released a video that goes through the code this is from .

   function blobtobuffer() {
  var reader = new FileReader();
  reader.readAsArrayBuffer(file.files[0]);
  reader.onload = function(event) {
    content = new Buffer(event.target.result.byteLength);
    var view = new Uint8Array(event.target.result);
    for (var i = 0; i < content.length; ++i) {
      content[i] = view[i];
    }
    return content;
  };
}
1 Like

Thanks, I will look into it.
I have tried FileReader Api and able to get the data uploaded in binary string format, but unable to upload file data from buffer array.

2 Likes