问题
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?
回答1:
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
.
来源:https://stackoverflow.com/questions/49232227/ajax-request-abort-on-large-query-string-elixir-plug