cancel
Showing results for 
Search instead for 
Did you mean: 

How to write file to a UNIX file system from XSJS?

Hi,

I want to write the xsjs response in a .dat file. I am able to write the response in .dat file and its being downloaded.

This is the below code.

 $.response.setBody(strF);
  $.response.contentType = 'application/vnd.ms-excel; charset=utf-16le';
  $.response.headers.set('Content-Disposition','attachment;filename=POC3.dat');
  $.response.status= $.net.http.OK;

But I want to restrict the download part and write this file "POC3.dat" in UNIX file system.

All these needs to be done through XSJS only. I am using XS advanced.

Any lead would be appreiated.

View Entire Topic
thomas_jung
Developer Advocate
Developer Advocate

Well if its a remove file system and its in an NFS mount, it shouldn't matter. The API will write to it as though its local and won't know the difference. If you are truly talking about a remote file system with no connection to your server then you would have to look at other technology like FTP to send the file to the remote server.

0 Kudos

Hi thomas,

Below is my code to write file in UNIX file path.

var fs = $.require('fs');
fs.writeFile('/INPUT/Home/folder1/folder2/helloWorld.txt', 'Hello World!', function (err) {
  if (err) {
  	return console.log(err);}
  console.log('Hello World > helloWorld.txt');
});

. we are using anonymous connection in XSA

Already UNIX path is mounted with HANA XSA DB

But still getting below error :

{ Error: EACCES: permission denied, open '/INPUT/Home/folder1/folder2/helloWorld.txt'

errno: -13,

code: 'EACCES',

syscall: 'open',

path: '/INPUT/Home/folder1/folder2/helloWorld.txt' }

thanks,

subrahmanya