Downloading Files from Server

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

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:

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

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

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