lukasl1991
lukasl1991

Reputation: 251

IBM Bluemix Liberty for Java public accessible directory

I develop a Java Web Application in IBM Bluemix using the Liberty for Java runtime. Within my application I create csv files, which I'd like to offer to my users as a download.

Unfortunately, I was not able to figure out where I have to write these files to. The url should be like http://myapp.eu-gb.mybluemix.net/test.csv or maybe http://myapp.eu-gb.mybluemix.net/download/test.csv

Do I have to specify a route in my server.xml?

Upvotes: 1

Views: 114

Answers (3)

jgawor
jgawor

Reputation: 96

Granted that you are fully aware of the issues related to the ephemeral file system in Cloud Foundry, you should be able to get the real path of your application on disk via ServetContext.getRealPath('/') call. Now, assuming you deployed a simple web application, you can write files to that location and have them accessible via http://<appName>.mybluemix.net/<file>. This should also work if you are using a non-root context path or want to put files in a sub-directory (as long as that sub-directory is not WEB-INF or META-INF).

Upvotes: 0

Tony BenBrahim
Tony BenBrahim

Reputation: 7290

Can you not download the file right away? Instead of writing the data to a FileWriter or FileOutputStream, write the data to a PrintWriter or OutputStream obtained from the HttpServletResponse.

For example:

response.setContentType("text/csv");
OutputStream outputStream=response.getOutputStream();
writeCsvData(outputStream);

or

response.setContentType("text/csv");
PrintWriter writer=response.getWriter();
writeCsvData(writer);

Upvotes: 0

Umberto Manganiello
Umberto Manganiello

Reputation: 3233

Please note that deploying an application in the Cloud (specifically to a Cloud Foundry-based platform) requires some considerations regarding the local file system:

  • Local file system storage is short-lived. When an application instance crashes or stops, the resources assigned to that instance are reclaimed by the platform including any local disk changes made since the app started. When the instance is restarted, the application will start with a new disk image. Although your application can write local files while it is running, the files will disappear after the application restarts.
  • Instances of the same application do not share a local file system. Each application instance runs in its own isolated container. Thus if your application needs the data in the files to persist across application restarts, or the data needs to be shared across all running instances of the application, the local file system should not be used.

If you want more information on this topic please take a look at Considerations for Designing and Running an Application in the Cloud.

I suggest you to take a look at the Object Storage service on Bluemix, that allows to store your data and retrieve it using an API.

Upvotes: 1

Related Questions