title: Image upload to filesystem in Grails
body: <p>I'm implementing a file upload functionality to a web-app in Grails.  This includes adapting existing code to allow multiple file extensions.  In the code, I've implemented a boolean to verify that the file path exists, but I'm still getting a FileNotFoundException that <code>/hubbub/images/testcommand/photo.gif (No such file or directory)</code></p>
  
  <p>My upload code is</p>
  
  <pre><code>def rawUpload = {       
      def mpf = request.getFile("photo")
      if (!mpf?.empty &amp;&amp; mpf.size &lt; 200*1024){
          def type = mpf.contentType
          String[] splitType = type.split("/")
  
          boolean exists= new File("/hubbub/images/${params.userId}")
  
          if (exists) {
              mpf.transferTo(new File("/hubbub/images/${params.userId}/picture.${splitType[1]}"))
          } else {
              tempFile = new File("/hubbub/images/${params.userId}").mkdir()
              mpf.transferTo(new File("/hubbub/images/${params.userId}/picture.${splitType[1]}"))
          }
  
      }
  }
  </code></pre>
  
  <p>I'm getting the exception message at </p>
  
  <pre><code>if (exists) {
          mpf.transferTo(new File("/hubbub/images/${params.userId}/picture.${splitType[1]}"))
  }
  </code></pre>
  
  <p>So, why is this error happening, as I'm simply collatating an valid existing path as well as a valid filename and extension?</p>