Tendos
Tendos

Reputation: 43

Is there a native function for downloading a file in neutralinojs that I can use?

When you right click on a download link in a neutralino app, there is a "download linked file" option which one selects then their file is downloaded. How can I call that function to download a file in my app.

Upvotes: 1

Views: 370

Answers (1)

EasyCodeTime
EasyCodeTime

Reputation: 11

One method I've been working with (which comes along with its own pitfalls) is using Powershell. The pitfall is that each user may have different versions of Powershell or different environment settings.

This method works on my development computer, but when testing on my laptop as a new user, it fails. But I have very little knowledge of Powershell and I think there is a way to make it work.

My progress so far:

// Create message for Neutralino to execute
let message ='powershell $download = Invoke-WebRequest -UseBasicParsing -Uri "'+insertCleanedURI+'" -OutFile Downloads/'+cleanName+'.fileExtension';


//Next run Neutralino's command execution method
let response = await Neutralino.os.execCommand({
    command: message
  });


// Capture the response from powershell which Neutralino will receive, and continue with logic
If (response.output.includes("Example Server Response") {
   // success, the file has downloaded to the folder & file name specified, do further stuff
} else {
   // failed, try to debug the issue
}

Edit: Realized you asked specifically for a native function, not using Powershell. This is how I found you question because I was wondering if I was doing this the hard way.

Upvotes: 1

Related Questions