How to recieve the image file in a controller where image is attached as parameter in Ws.url?

253 views Asked by At

The image file is attahced as a parameter through the Webservice Ws.url("controller action").files(imageFile) in play framework 1.2.4. How to receive that image file in that controller? Can anyone please help me on this.

1

There are 1 answers

7
Werner Kvalem VesterĂ¥s On

Let us post two files:

WS.url("http://127.0.0.1:9000/process")
  .files(new File("kitten.jpg"), new File("dog.jpg"))
  .post();

The controller method looks like this:

public static void process(File dummy) {
  List<Upload> uploads = (List<Upload>) request.args.get("__UPLOADS");

  for (Upload upload : uploads) {
    System.out.println("Uploaded file name:         " + upload.getFileName());
    System.out.println("Uploaded file is stored as: " + upload.asFile());
  }
}

Very ugly, but this is the only way that I got it to work. The dummy parameter must be there, otherwise the uploads request argument will be null.

The images are accessible in different ways through the Upload objects.