Problem in getting file contents when application is deployed on server

The following code is inside index.html of my application and it works when I access my app via web browser in the following manner:

file:///C:/jack/testing/ui/static/index.html

By works, I mean, I can see the 3 files getting downloaded in csv format with 3KB of size.

const requests = [
  'file1_1555077233.csv',
  'file2_1555077233.csv',
  'file3_1555077233.csv'
].map(file => {
  return fetch('file:///C:/jack/file/JACK/' + file)
    .then(response => response.text())
    .catch(console.error)
})

Promise.all(requests)
  .then(contents => {
    const zip = new JSZip()

    contents.forEach((content, index) => {
      zip.file(`file-${index}.csv`, content)
    })

    return zip.generateAsync({ type: 'blob' })
  })
  .then(blob => {
    saveAs(blob, 'files.zip')
  })

Scenario 1:
However, when I have my application deployed as WAR file in tomcat, I access my application in the following manner from the web browser :

http://localhost:8080/testing/index.html

In this scenario, the above javascript code doesn’t completely work. I mean, it downloads the 3 files but the size of the file is 0KB. This makes sense since I am accessing the website over HTTP and my files
should be served by the server.

On windows, how should I modify this line of code return fetch('file:///C:/jack/file/JACK/' + file) so that it starts working in this scenario.

Scenario 2:

Similarly, when I deployed the WAR in the tomcat running on RHEL server, I am accessing my application in the following manner:

https://myserver.com/testing/index/html

In this scenario also, I am noticing empty files are getting downloaded when I used the above code with this change:

return fetch(‘/srv/users/JACK’ + file)

Move the file so that it is somewhere on your local server.

Thanks. So for tomcat server, I am wondering where should it go?

That will require someone else to come along that knows something about tomcat.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.