I have a system where a tar file is received by an Elixir/Phoenix app, downloaded and an extracted, yielding a LaTeX file and a directory of image files. pdflatex
is run twice and the location of the resulting pdf file is shipped back to the client. The client can then request the file. All this works on my laptop – but not on Heroku. I do get a message from the server indicating that extraction and pdflatex have succeeded. (See code at end). Also, the message below tells me that the tar achive has been saved.
However, when the client requests the file, it is not found.
I know the Heroku storage is ephemeral. However, for the short time I need these files, should generally be ok.
HEROKU LOG:
2019-01-12T22:27:44.217500+00:00 app[web.1]: params for 'process': %{"filename" => "bras_and_kets"}
2019-01-12T22:27:44.217507+00:00 app[web.1]: 22:27:44.212 request_id=bfb4cecb-7738-44f9-8838-1b27f968898c [info] POST /api/print/pdf/bras_and_kets
2019-01-12T22:27:44.217509+00:00 app[web.1]: BODY: <<98, 114, 97, 115, 95, 97, 110, 100, 95, 107, 101, 116, 115, 46, 116, 101, 120,
2019-01-12T22:27:44.217511+00:00 app[web.1]: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2019-01-12T22:27:44.217513+00:00 app[web.1]: 0, 0, 0, 0, 0, 0, 0, ...>>
2019-01-12T22:27:44.217730+00:00 app[web.1]: PATH: printfiles/bras_and_kets/bras_and_kets.tar
2019-01-12T22:27:44.237525+00:00 app[web.1]: XX, FILE EXISTS: printfiles/bras_and_kets/bras_and_kets.tar
2019-01-12T22:27:44.338354+00:00 app[web.1]: 22:27:44.337 request_id=bfb4cecb-7738-44f9-8838-1b27f968898c [info] Sent 200 in 125ms
2019-01-12T22:28:14.005012+00:00 heroku[router]: at=info method=GET path="/print/pdf/bras_and_kets" host=nshost.herokuapp.com request_id=4c2b7a3a-6acb-431b-9d73-6571833ff720 fwd="24.92.138.170" dyno=web.1 connect=1ms service=38ms status=200 bytes=611 protocol=https
2019-01-12T22:28:14.005494+00:00 app[web.1]: 22:28:14.001 request_id=4c2b7a3a-6acb-431b-9d73-6571833ff720 [info] GET /print/pdf/bras_and_kets
2019-01-12T22:28:14.006072+00:00 app[web.1]: 22:28:14.005 request_id=4c2b7a3a-6acb-431b-9d73-6571833ff720 [info] Sent 200 in 4ms
CONTROLLER FUNCTION 1: handle POST request sending tar archive
def process(conn, params) do
IO.inspect params, label: "params for 'process'"
{:ok, body, conn} = Plug.Conn.read_body(conn, length: 3_000_000)
IO.inspect body, label: "BODY"
bare_filename = params["filename"]
tarfile = "#{bare_filename}.tar"
texfile = params["filename"] <> ".tex"
prefix = "printfiles/#{params["filename"]}"
{:ok, cwd} = File.cwd
File.mkdir_p prefix
tar_path = "#{prefix}/#{tarfile}"
IO.puts "PATH: " <> tar_path
{:ok, file} = File.open tar_path, [:write]
IO.binwrite file, body
File.close file
case File.read(tar_path) do
{:ok, body} -> IO.puts "XX, FILE EXISTS: #{tar_path}"
{:error, reason} -> IO.puts "XX, NO SUCH FILE: #{tar_path}"
end
# System.cmd("tar", ["xvf", path])
System.cmd("tar", ["-xf", tar_path, "-C", prefix ])
File.cd prefix
System.cmd("pdflatex", ["-interaction=nonstopmode", texfile])
System.cmd("pdflatex", ["-interaction=nonstopmode", texfile])
File.cd cwd
conn |> render("pdf.json", url: bare_filename)
end
CONTROLLER FUNCTION 2: get the pdf file:
def display_pdf_file(conn, %{"filename" => filename}) do
path = "printfiles/#{filename}/#{filename}.pdf"
case File.read(path) do
{:ok, body} -> Plug.Conn.send_file(conn, 200, path)
{:error, reason} -> conn |> render("pdf_error.html", path: "Sorry, couldn't find the PDF file.")
end
end
Also: I see no directory printfiles
at the root level of the Heroku directory, where I expect it to be.