Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing with StreamingParser fails with file 86kb #8

Closed
Pato05 opened this issue Mar 24, 2020 · 3 comments
Closed

Parsing with StreamingParser fails with file 86kb #8

Pato05 opened this issue Mar 24, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Pato05
Copy link
Contributor

Pato05 commented Mar 24, 2020

I have a form which contains an input file. If I put an image of ~86kb it produces many PHP warning of strpos "Offset not contained in string" and fails with error 500, because it throws "Request body ended unexpectedly".
Using MadelineProto too with Amp.
log.txt

@kelunik kelunik added the bug Something isn't working label Mar 24, 2020
@kelunik kelunik self-assigned this Mar 24, 2020
@Pato05
Copy link
Contributor Author

Pato05 commented Mar 24, 2020

About the increasing of the size limit? Maybe adding a method to do so?

@kelunik
Copy link
Member

kelunik commented Mar 24, 2020

There's already a method for that: $request->getBody()->increaseSizeLimit(...). I've added an example to show how it works:

$request->getBody()->increaseSizeLimit(120 * 1024 * 1024);
$parser = new StreamingParser;
$fields = $parser->parseForm($request);
while (yield $fields->advance()) {
/** @var StreamedField $field */
$field = $fields->getCurrent();
$bytes = yield $field->buffer();
if ($field->getName() === 'test') {
$html = "<html lang='en'><a href='/'>← back</a><br>sha1: " . \sha1($bytes) . "<html>";
return new Response(Status::OK, [
"content-type" => "text/html; charset=utf-8",
], $html);
}
}

@kelunik kelunik assigned trowski and unassigned kelunik Mar 24, 2020
@Pato05
Copy link
Contributor Author

Pato05 commented Mar 24, 2020

Oh ok, so just call $request->getBody(). Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants