2

I deployed my play framework 2.1 application on appfog(same issue also exists on cloudfoundry since they are essentially the same). My application allow file upload, but I have encountered an error getting the file. It works fine when I run locally with play run.

My code is as follows:

MultipartFormData body = request().body().asMultipartFormData();
FilePart midi = body.getFile("midi");
File file = midi.getFile();

The error message in log is:

play.api.Application$$anon$1: Execution exception[[IOException: No such file or directory]]
    at play.api.Application$class.handleError(Application.scala:289) ~[play.play_2.10-2.1.0.jar:2.1.0]
    at play.api.DefaultApplication.handleError(Application.scala:383) [play.play_2.10-2.1.0.jar:2.1.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleAction$1$4$$anonfun$apply$28.apply(PlayDefaultUpstreamHandler.scala:391) [play.play_2.10-2.1.0.jar:2.1.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleAction$1$4$$anonfun$apply$28.apply(PlayDefaultUpstreamHandler.scala:391) [play.play_2.10-2.1.0.jar:2.1.0]
    at scala.Option.map(Option.scala:145) [org.scala-lang.scala-library-2.10.0.jar:na]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$handleAction$1$4.apply(PlayDefaultUpstreamHandler.scala:391) [play.play_2.10-2.1.0.jar:2.1.0]
Caused by: java.io.IOException: No such file or directory
    at java.io.UnixFileSystem.createFileExclusively(Native Method) ~[na:1.7.0_11]
    at java.io.File.createTempFile(Unknown Source) ~[na:1.7.0_11]
    at java.io.File.createTempFile(Unknown Source) ~[na:1.7.0_11]
    at play.api.libs.Files$TemporaryFile$.apply(Files.scala:60) ~[play.play_2.10-2.1.0.jar:2.1.0]
    at play.api.mvc.BodyParsers$parse$Multipart$$anonfun$handleFilePartAsTemporaryFile$1.apply(ContentTypes.scala:624) ~[play.play_2.10-2.1.0.jar:2.1.0]
    at play.api.mvc.BodyParsers$parse$Multipart$$anonfun$handleFilePartAsTemporaryFile$1.apply(ContentTypes.scala:622) ~[play.play_2.10-2.1.0.jar:2.1.0]

It looks like that it's having problem creating a temporary file from the multipartForm. Is there a good way to solve this? My application is stored on AWS, configured through appfog.

  • This appears to be an issue with CF, and not Play. Play is simply calling java.io.File to create a temporary file. My recommendation is to re-ask the question in the context of creating temporary files on CF. – Christopher Hunt Mar 11 '13 at 00:40
  • Is your app trying to store the file uploaded on the local storage same as where the app is deployed? Not familiar with appfog but for cloudfoundry it is not recommended to use the local file system for any persistency as it is inaccessible by multiple instances and is recognised as transient which would be gone whenever the app is restarted. – William Gu Mar 11 '13 at 03:42
  • Thank you for the replies. I agree that this appears to be a problem with creating temporary files on CF. I am only using this temporary file for the application logic and the file will be discarded after the computation is finished. But at this point, it looks like such temporary file can not be created. – Peter Huang Mar 11 '13 at 18:59
  • Is this solved, Peter? I remember seeing an additional comment yesterday but is gone now. – William Gu Mar 13 '13 at 03:22
  • Yes I thought it was caused by the fact that some files in the project are not included in the jar file after "play dist". But after I fix that, the temporary file problem still exist. It seems that play is not able to create temporary files on cloudfoundry (at least for multipart form submissions). Right now I can only start httpserver on my own machine. – Peter Huang Mar 13 '13 at 19:52
  • Also, can you let us know how many instances does your app have? The uploaded file cannot be accessed by other instances in a different session. Can you try only 1 instance if you have more than 1? – William Gu Mar 18 '13 at 23:43
  • My application only has one instance. Is there a way that you can take a closer look at my deployment through my account maybe? – Peter Huang Mar 20 '13 at 00:41
  • This issue has been discovered by another developer. Here is the link: http://grokbase.com/t/gg/play-framework/133s5rhq0c/play-2-1-multipartformdata-file-upload-issue-on-appfog – Peter Huang Apr 04 '13 at 05:50
  • An "Official" answer is now given: https://github.com/hakandilek/publicplay/issues/110. Thank you for following the question. – Peter Huang Apr 04 '13 at 06:30

0 Answers0