How to pass/stream content from an another HTTP Server to a client

Hallo all,

I have the following problem. I use in an app a headless CMS and do not want to open this CMS to the outside world. It is no problem so far, but if I need images and other content resources from my headless CMS, it troubles me in case of SVG and other files.

For Example: I have a image, stored in my CMS. I can get this image using the path http://hostname.cms:1334/uploaded/image_name.svg

But if I do not want to open this port, my Phoenix App has to serve the image to the outside. I can get over Phoenix my image. No problem. The content is:

<svg id="svg134546" version="1.1" width="134.78423mm" xmlns:sodipodi="" inkscape:export-filename="logo_2.svg" inkscape:export-ydpi="96" height="187.13409mm" viewBox="0 0 134.78423 187.13409" xmlns:inkscape="" xmlns:svg=...

But now my Phoenix ServerApp has to take this content and server directly to the client. Here starts my trouble, because a Phoenix View can only render to HTML or JSON. But how dealing with any binary content??? What can I use instead?

I think of a usecase like:

defmodule GeosWeb.ImageController do
  use GeosWeb, :controller
  import Plug.Conn
  import Geos.Strapi

  def index(conn, %{"file" => filename}) do
    downloaded = get_uploaded_image(filename)

    |> render("here what to do??? to serve the content directly without root.html.heex and so on ... ???")


Thank you so far,

send_resp(conn, 200, file) is what you’re looking for. You can just skip anything render/3 related.

1 Like


Thank you so much! It works. The function is not send but send_resp(conn, 200, file).

Have a nice day!!!


Fixed :slight_smile:

1 Like