Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala play framework file upload error

I am using this tutorial to upload a file in my play framework application. I am using the exact same code but I get following error.

[IOException: Path(/Users/hrishikeshparanjape/Desktop) exists but replace parameter is false]

Following is my code:

def upload = Action(parse.multipartFormData) { request =>
        request.body.file("picture").map { picture =>
            import java.io.File
            val filename = picture.filename 
            val contentType = picture.contentType
            picture.ref.moveTo(new File("/Users/hrishikeshparanjape/Desktop/"))
            Ok("File uploaded")
        }.getOrElse {
            Redirect(routes.Application.index).flashing(
                    "error" -> "Missing file"
                    )
        }
    }

I am stuck here please help.

EDIT: Here is my full stack trace:

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[IOException: Path(/Users/hrishikeshparanjape/Desktop) exists but replace parameter is false]]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.0.2]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.0.2]
    at akka.actor.Actor$class.apply(Actor.scala:318) [akka-actor.jar:2.0.2]
    at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.0.2]
    at akka.actor.ActorCell.invoke(ActorCell.scala:626) [akka-actor.jar:2.0.2]
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:197) [akka-actor.jar:2.0.2]
Caused by: java.io.IOException: Path(/Users/hrishikeshparanjape/Desktop) exists but replace parameter is false
    at scalax.file.Path$.fail(Path.scala:168) ~[scala-io-file_2.9.1.jar:0.4.0]
    at scalax.file.Path.moveTo(Path.scala:1089) ~[scala-io-file_2.9.1.jar:0.4.0]
    at play.api.libs.Files$.moveFile(Files.scala:76) ~[play_2.9.1.jar:2.0.2]
    at play.api.libs.Files$TemporaryFile.moveTo(Files.scala:30) ~[play_2.9.1.jar:2.0.2]
    at controllers.Application$$anonfun$upload$1$$anonfun$apply$1.apply(Application.scala:17) ~[classes/:2.0.2]
    at controllers.Application$$anonfun$upload$1$$anonfun$apply$1.apply(Application.scala:13) ~[classes/:2.0.2]
[info] Compiling 1 Scala source to /Users/hrishikeshparanjape/git-public/printit/target/scala-2.9.1/classes...
like image 298
hrishikeshp19 Avatar asked Aug 05 '12 07:08

hrishikeshp19


1 Answers

Looks like you need to specify the complete file name for moveTo

picture.ref.moveTo(new File(
  "/Users/hrishikeshparanjape/Desktop/" + picture.filename))
like image 127
Kim Stebel Avatar answered Nov 02 '22 23:11

Kim Stebel