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