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

Exception when uploading binary files #27

Closed
Xpam opened this issue Nov 4, 2013 · 10 comments
Closed

Exception when uploading binary files #27

Xpam opened this issue Nov 4, 2013 · 10 comments

Comments

@Xpam
Copy link

Xpam commented Nov 4, 2013

When using HTML form to upload binary file an exception is thrown in debugbar:

json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument

In \vendor\maximebf\debugbar\src\DebugBar\JavascriptRenderer.php

protected function getAddDatasetCode($requestId, $data, $suffix = null)
{
    $js = sprintf("%s.addDataSet(%s, \"%s\"%s);\n",
        $this->variableName,
        json_encode($data), //-------------> row 790

I assume this is used to display the POST data but it can't chew up the binary.

@barryvdh
Copy link
Owner

barryvdh commented Nov 4, 2013

Hmm, not really sure. Can you post the code from your form? The FILES array isn't usually shown. Are you passing the file to a view or something?
Just the regular config?

@Xpam
Copy link
Author

Xpam commented Nov 4, 2013

This is the form:

{{ Form::open(array('url' => URL::to("downloadscp/upload"), 'files' => true)) }}
...some text inputs....
{{ Form::file("file") }}
{{ Form::submit("Save", array("class" => "btn fright")) }}
{{ Form::close() }}

Controller:

$validator = ValidatorService::validateFileUpload();
if ($validator->passes())
{
$file = Input::file("file");
$dl = new Download;
$dl->display_name = e(Input::get("display_name"));
$dl->filename = $file->getClientOriginalName();
$dl->mime = $file->getMimeType();
$dl->size = $file->getClientSize();
$dl->description = e(Input::get("description"));
$dl->link=null;
$dl->category_id = Input::get("category");
$dl->priority = Input::get("priority");
$dl->added_time = date("Y-m-d H:i:s");
$dl->added_by = Auth::user()->id;
$dl->num_downloads = 0;
$path = $file->getRealPath();
$dl->data = file_get_contents($path);
$dl->sha1 = sha1_file($path);
$dl->save();
success("File uploaded");
return Redirect::to("downloadscp/upload");
}
else
{
return Redirect::to("downloadscp/upload")->withErrors($validator)->withInput();
}

No special configuration as far as I know.

@barryvdh
Copy link
Owner

barryvdh commented Nov 4, 2013

And a specific file that is causing trouble, or all files?
Op 4 nov. 2013 18:02 schreef "Eurobattle.net" notifications@github.com:

This is the form:

{{ Form::open(array('url' => URL::to("downloadscp/upload"), 'files' =>
true)) }}
...some text inputs....
{{ Form::file("file") }}
{{ Form::submit("Save", array("class" => "btn fright")) }}
{{ Form::close() }}

Controller:

$validator = ValidatorService::validateFileUpload();
if ($validator->passes())
{
$file = Input::file("file");
$dl = new Download;
$dl->display_name = e(Input::get("display_name"));
$dl->filename = $file->getClientOriginalName();
$dl->mime = $file->getMimeType();
$dl->size = $file->getClientSize();
$dl->description = e(Input::get("description"));
$dl->link=null;
$dl->category_id = Input::get("category");
$dl->priority = Input::get("priority");
$dl->added_time = date("Y-m-d H:i:s");
$dl->added_by = Auth::user()->id;
$dl->num_downloads = 0;
$path = $file->getRealPath();
$dl->data = file_get_contents($path);
$dl->sha1 = sha1_file($path);
$dl->save();
success("File uploaded");
return Redirect::to("downloadscp/upload");
}
else
{
return
Redirect::to("downloadscp/upload")->withErrors($validator)->withInput();
}

No special configuration as far as I know.


Reply to this email directly or view it on GitHubhttps://github.com//issues/27#issuecomment-27702221
.

@Xpam
Copy link
Author

Xpam commented Nov 4, 2013

Yes, it seems that file is being passed back to the view because of ->withInput()
Only binary files fail. Text files are ok. I am checking now why exactly the validator fails in the first place.

edit: see next comment

@Xpam
Copy link
Author

Xpam commented Nov 4, 2013

Ok, I changed the redirect to ->withInput(Input::except("file")); so now the file is not being passed back if validator fails.

But this does not seem to be the problem. The validator passes fine and all steps are completed, all info is in the database. Just the debugbar crashes, everything else is executing fine.

@barryvdh
Copy link
Owner

barryvdh commented Nov 4, 2013

Can you try disabling the data collectors in the debugbar config to see
what collector is causing trouble?
Op 4 nov. 2013 18:17 schreef "Eurobattle.net" notifications@github.com:

Ok, I changed the redirect to ->withInput(Input::except("file")); so now
the file is not being passed back if validator fails.

But this does not seem to be the problem. The validator passes fine and
all steps are completed, all info is in the database. Just the debugbar
crashes, everything else is executing fine.


Reply to this email directly or view it on GitHubhttps://github.com//issues/27#issuecomment-27703470
.

@Xpam
Copy link
Author

Xpam commented Nov 4, 2013

It is the db collector.. and I know why. I am saving the files in LARGEBLOB field in database. This must be the problem.

@barryvdh
Copy link
Owner

barryvdh commented Nov 4, 2013

Ok, pushed a possible fix to php-debugbar upstream.

@barryvdh
Copy link
Owner

barryvdh commented Nov 8, 2013

Is merged, is this better?

@barryvdh barryvdh closed this as completed Nov 8, 2013
@Xpam
Copy link
Author

Xpam commented Nov 8, 2013

I will do some tests and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants