2

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?

16
  • Did you post it as 'mutipart' type? Commented Mar 12, 2018 at 10:44
  • no? why would it be multipart? Its a string only Commented Mar 12, 2018 at 10:44
  • If you post it as string ,you should change the length in Plug.Parsers. Commented Mar 12, 2018 at 10:46
  • PS, I don't find the query_string_length option in the plug project. Commented Mar 12, 2018 at 10:47
  • 1
    We are sending AJAX request with JSON data. Commented Mar 12, 2018 at 11:50

1 Answer 1

2

As you are sending AJAX request with JSON data, you should put the length config of json in the plug.

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

I suppose you will not put the data in the query string of the post, so the query_string_length - the maximum allowed size for query strings is not needed.


---Original answer---

For plug version around 1.4.3 and have no query_string_length option.

When you post the data as string, you are using Plug.Parsers.

If you are willing to process larger requests, please give a :length to Plug.Parsers.

You should change the code query_string_length: 1_000_000 to length: 20_000_000.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.