Downloading Files from Server

Forum to discuss the new web client version of Servoy.

Downloading Files from Server

Postby dev-ws-011 » Mon Mar 28, 2022 7:18 am

Hi All,

I am working with NG Desktop Client. I have come across an issue while working with download functionality. Previously to download files, file plugin (plugins.file.streamFilesFromServer(dir, list, callbackFunction)) was used but its not working for NG Desktop client. I have looked into ng desktop file utils but no such method there.

Any help shall be highly appreciated.

Thanks
Servoy Developer
dev-ws-011
 
Posts: 73
Joined: Fri Oct 21, 2016 8:23 am

Re: Downloading Files from Server

Postby robert.edelmann » Mon Mar 28, 2022 7:17 pm

What do you mean with "download", what is the source you want do download data from?

If it's a file from an url, you could do this:
Code: Select all
/**
* @param {String} url
* @param {String} fileName
*
* @properties={typeid:24,uuid:"F5285CBF-8BB6-4274-A4DF-4EE95B73D260"}
*/
function downloadDocument(url, fileName) {
   var bytes = plugins.http.getMediaData(url)
   var homePath = plugins.ngdesktopfile.homeDir() + java.io.File.separator + fileName;
   var fileOptions = {
      title: 'save file',
      defaultPath: homePath,
      buttonLabel: 'Ok'
   };
   var filePath = plugins.ngdesktopfile.showSaveDialogSync(fileOptions)
   if (filePath) {
      filePath = filePath.replace(/\\/g, '/');
      plugins.ngdesktopfile.writeFile(filePath, bytes);
      scopes.Dokumente.openNGDocument(filePath);
   }
}


if you got the data as bytes (in this example in a variable of the same name) you could do something like this:
Code: Select all
var filename = 'test.doc';
var folderName = plugins.ngdesktopfile.homeDir();
var targetFileName = folderName + java.io.File.separator + fileName;
targetFileName = targetFileName.replace(/\\/g, "/");
plugins.ngdesktopfile.writeFile(targetFileName, bytes);
if (targetFileName) {
    plugins.ngdesktopfile.openFile(targetFileName);
}
mit freundlichen Grüßen
Robert Stefan Edelmann
User avatar
robert.edelmann
 
Posts: 91
Joined: Wed Aug 14, 2013 6:12 pm

Re: Downloading Files from Server

Postby dev-ws-011 » Tue May 10, 2022 2:57 pm

Thanks for the assistance.

I was considering some direct method to provide download functionality. Read file in byte array and then write file worked for me .

Regards
Servoy Developer
dev-ws-011
 
Posts: 73
Joined: Fri Oct 21, 2016 8:23 am


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 9 guests