Reputation: 251
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
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
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
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:
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