0

I deployed a servlet in Bluemix (bluemix-liberty) that saves a file (sent from UI) in the Bluemix server. I used below code but I am getting permission denied exception:

DiskFileItemFactory fileFactory = new DiskFileItemFactory();
File filesDir = new File("/");
fileFactory.setRepository(filesDir);
this.uploader = new ServletFileUpload(fileFactory); 

I am getting the following exception:

Exception in uploading file. Processing of multipart/form-data request failed. /upload_3d1b2086_152b5c954a4__8000_00000000.tmp (Permission denied)

Is there any option to get permission to save file in Bluemix or any other way to save a file in the Bluemix server? Thanks in advance.

ralphearle
  • 1,696
  • 13
  • 18
  • 1
    Bluemix and Cloudfoundry are based on the concept of 12 factor apps. You should not be storing files on the filesystem. Use some kind of service instead (e.g. a document database or even a relational database, or amazon s3, etc). Multiple instances of your scaled application will not have access to the same files, also when restarting your app, it will be scheduled on a different container, and the files will be gone. – user152468 Feb 06 '16 at 09:31
  • Here is some documentation on why not to store files on the filesystem in cloud foundry: https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html. And how to do it right. – user152468 Feb 06 '16 at 09:35
  • See also this question: https://developer.ibm.com/answers/questions/16880/storing-file-on-bluemix.html – user152468 Feb 06 '16 at 09:37
  • Actually I debugged a little bit, the issue is not creating a file in the server. It allow me to create file if i use code like File file = new File("/tmp.wav"); The issue is it does not allow the servlet to accept the file that is uploaded from the UI. Any pointer in this?. I need to upload a audio file and need to store it at server or DB for temporary purpose. – user3398439 Feb 06 '16 at 10:30
  • Can you try uploading a small file (<100KB)? – Ram Vennam Feb 06 '16 at 17:17
  • If you have to spool it to disk, don't spool it to the root of the filesystem. – covener Feb 08 '16 at 16:23

1 Answers1

0

As the commenters already pointed out, it would be better to store files using a service called by your CF App Instance. One flexible candidate would be Objectstorage Service. An example on how to store and retrieve files in Java can be found here: https://developer.ibm.com/recipes/tutorials/connecting-to-ibm-object-storage-for-bluemix-with-java/ Another approach would be to store a file as attachment in Cloudant NoSQL DB. The Bluemix Java or Node.js Cloudant Boilerplate shows this as example: https://console.eu-gb.bluemix.net/catalog/starters/java-cloudant-web-starter/

Rene Meyer
  • 90
  • 6