# Downloading Files from Server

**URL:** <https://forum.servoy.com/t/downloading-files-from-server/20720>\
**Category:** Questions\
**Created:** [March 28, 2022, 5:18am UTC](https://forum.servoy.com/t/downloading-files-from-server/20720 "2022-03-28T05:18:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev-ws-011](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dev-ws-011](https://forum.servoy.com/u/dev-ws-011)\
**Post date:** [March 28, 2022, 5:18am UTC](https://forum.servoy.com/t/downloading-files-from-server/20720/1 "2022-03-28T05:18:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robert.edelmann](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/robert.edelmann/32/4494_2.png) [@robert.edelmann](https://forum.servoy.com/u/robert.edelmann)\
**Post date:** [March 28, 2022, 5:17pm UTC](https://forum.servoy.com/t/downloading-files-from-server/20720/2 "2022-03-28T17:17:18Z")

</div>

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:

```auto
/**
 * @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:

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![dev-ws-011](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dev-ws-011](https://forum.servoy.com/u/dev-ws-011)\
**Post date:** [May 10, 2022, 12:57pm UTC](https://forum.servoy.com/t/downloading-files-from-server/20720/3 "2022-05-10T12:57:34Z")

</div>

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
