AJAX request abort on large query string Elixir Plug

I am sending 2 large query string in AJAX requests, which are basically, a Base64 encoding of a jpeg(s). When the Camera is not a high-resolution one, AJAX request doesn’t abort.

At first, I thought its a Nginx issue, Because I was getting an error as request entity too large I resolved it, Then I made changes to my Plug as

  plug Plug.Parsers,
    parsers: [
      :urlencoded,
      {:multipart, length: 20_000_000},
      :json
      ],
    pass: ["*/*"],
    query_string_length: 1_000_000,
    json_decoder: Poison

After defining query_string_length, Now I am not getting any errors like above but ajax request still abort.

Base64 encoding string size is 546,591 bytes or max.

I have tried to increase the AJAX request timeout to a very large timespan as well but it still fails. And I don’t have any clue where the problem is right now.

How can we receive long strings in Plug?

Some of few answers on StackOverflow about this issue where people used AJAX and PHP, suggesting to change post_max_size, How can we do that in Elixir Plug?

I think You can configure this in endpoint.ex. Add length params to Plug.Parsers…

  plug(
    Plug.Parsers,
    parsers: [:urlencoded, :multipart, :json],
    pass: ["*/*"],
    json_decoder: Poison,
    #
    # Increase the size for file uploads
    # https://chodounsky.net/2015/06/05/increase-request-length-in-phoenix-to-upload-large-files/
    # https://hexdocs.pm/plug/Plug.Parsers.html
    #
    length: 100_000_000
  )
1 Like

Okay you mean only length? and not query_string_length?

I had the same problem, sending base64 hd photo from a mobile. This is how I solved this…

1 Like