0

A controller function of My play application can create a pdf file if a link within the application is used. This is working very well in development mode. However, I need to know where to save that pdf file so if my application is running in production mode then that pdf file will be able to be created by my controller's function and also be downloadable. I was thinking on using:

import com.typesafe.sbt.packager.MappingsHelper._
    mappings in Universal ++= directory(baseDirectory.value / "public")

in my build.sbt file and somehow save that pdf file there but as I understand this folder is mainly for static resources needed before the application is running. Am I right? Is there a better way?

Jose Cabrera Zuniga
  • 2,348
  • 3
  • 31
  • 56

1 Answers1

2

There is answer for custom folder declaration here, and if you are running your application from the bin folder and you are using Process, the commands are executed one folder up; however I think for cleaner architecture you should do this:

Don't save your PDF where the application is running

This should be obvious, simply because for every deployment you have to copy paste your pdf to a the new deployment folder. And, if you are only generating one and only one pdf, then the addition of a folder is not necessary. The simplest form, you can tackle this, while having a clean architecture is to use a third-party service (e.g., AWS S3); you could then save the pdf, to a unique address (aka Bucket in S3); with a unique format name (e.g., useraname-date.pdf).

In S3, you could use a clean path something line username/billing/month/; then you can add the file there; so you are doing three things: 1. you are organizing the pdf storage and 2. you could create a history of the storage. 3. you know for what month you can access the right pdf.

One last point here: scalability. You could simply now run more than one instance of the application and both can use the same resources.

o-0
  • 1,713
  • 14
  • 29
  • I like your answer. However, since we are using Docker containers we decided to use absolute folders for both prod and dev out of the application folder so only the controller method is going to be able to access that folder. Thanks – Jose Cabrera Zuniga Aug 31 '18 at 15:07