0

When I upload images localhost there is no problem on uploading. But when deployed on server (dokku on digitalocean) server returns error 500 with NoSuchFile exception. What is my mistake?

def upload = Action(parse.multipartFormData) { request =>
      request.body.file("file").map { picture =>
         import java.io.File
         val filename = picture.filename
         val extension = Files.getFileExtension(filename)
         val contentType = picture.contentType
         Logger.warn(extension)
         val newFileName = s"${UUID.randomUUID}.$extension"
         val uniqueFile = new File(s"public/pictures/$newFileName")
         picture.ref.moveTo(uniqueFile)
         Ok(newFileName)
  }.getOrElse {
         Ok("error")
  }
}

error log:

@6oo5djflc - Internal server error, for (POST) [/template/uploadLogo]

play.api.UnexpectedException: Unexpected exception[NoSuchFileException: /tmp/playtemp71801546008559360/multipartBody6913035116351905525asTemporaryFile -> public/pictures/1046fe85-d910-41f4-a52f-53a6f2506d76.png]

ccheneson
  • 49,072
  • 8
  • 63
  • 68
  • Does the destination directory exists? Also, use your public directory (or any other inside the application directory) to store uploaded files is a bad idea. What happens the next time you deploy a new version of your application? – marcospereira Jan 19 '16 at 14:34
  • Yes, i changed file upload method to the amazon s3 – baytbybayt Jan 20 '16 at 21:39

1 Answers1

0

For those ending up here, adding application.root in front of the path of new File(..) solved the problem for me, i.e.

new File(s"${application.path}/the_actual_filename.jpg")

markusz
  • 1
  • 1