How Lagom java use Play Java Controller

java

(Yang Jun) #1

Lagom 1.3.x for java

user Play java Controller download file

public class FileController extends Controller {

  /**
   * download
   * @param f filename
   * @return Result
   * @throws FileNotFoundException
   */
  public Result download(String f) throws FileNotFoundException {
    final InputStream is = new BufferedInputStream(new FileInputStream(f));
    return ok(is).withHeader("Content-Disposition", "attachment; filename=1.txt");
  }

}

routes file

GET    /api/files  ytd.pdnms.controllers.FileController.download(f: String)
->     /           com.lightbend.lagom.javadsl.server.LagomServiceRouter

(Ignasi Marimon-Clos) #2

Hi @yangjun,

this is a great contribution. The case you describe is not very common but it comes up quite often and, unfortunately, it’s not very documented.

We developed an example application to demonstrate how to handle file upload (in scala dsl) byt combining a Play controller in Lagom.

It’s in https://github.com/lagom/lagom-recipes/tree/master/file-upload/file-upload-scala-sbt. I’ll leave the link here so it can be located too.

Thanks!


(Yang Jun) #3

I see exampe, how do used java? demo is scala.
thanks.


(Irina Lebedeva) #4

Hi @yangjun,
Have you find the answer to your question how to upload file in Lagom service with java?