Closed Marwelln closed 10 years ago
Update - check out @mantasradzevicius post of @lucasmichot 's fix below. It's more holistic and isn't based on javascript or editing core files.
+1
I've been having trouble with laravel-stapler after manually migrating and setting it up. Same result if using a multipart form type.
My solution is hilarious but doesn't require editing core files if you're okay with alienating non-js users:
$(document).ready ->
$('.profile-form').on 'submit', (e) ->
$photoInput = $('.profile-photo-input input')
$photoInput.remove() if $photoInput.val() == ""
return true
Essentially, I remove the input if the value hasn't been set to anything. Super hacky but it might fit for someone in the interim.
+1
+1
Hoping for a fix soon.
I was about to create an issue for this too. I wrote a test case for it:
In HttpRequestTest.php:
public function testInputWithEmptyFilename()
{
$invalidFiles = [
'file' => [
'name' => null,
'type' => null,
'tmp_name' => null,
'error' => 4,
'size' => 0
]
];
$baseRequest = \Symfony\Component\HttpFoundation\Request::create('/?boom=breeze', 'GET', array('foo' => array('bar' => 'baz')), array(), $invalidFiles);
$request = Request::createFromBase($baseRequest);
}
+1
+1
+1
+1
+1
+1
+1
+1
+1
Thanks @youanden for the temporary JS fix. Works a treat.
@alexleonard glad I could be of service.
@youanden I used your fix, did the trick until a fix came out, thanks!
I've rewritten it a little with jquery to work across all file forms:
$('form[enctype="multipart/form-data"]').on('submit', function(e){
$(this).find('input[type=file]').each(function(){
var file = $(this);
if (file.val() == "") file.remove();
});
return true;
});
+1 and +1 for marking it as important
+1
As a temp solution how to apply this fix:
App\Http\Request
class which extends Illuminate\Http\Request
(example below)Example
namespace App\Http;
use Illuminate\Http\Request as LaravelRequest;
class Request extends LaravelRequest
{
/**
* {@inheritdoc}
*/
public function duplicate(
array $query = null,
array $request = null,
array $attributes = null,
array $cookies = null,
array $files = null,
array $server = null
) {
$files = array_filter((array)$files);
return parent::duplicate(
$query,
$request,
$attributes,
$cookies,
$files,
$server
);
}
}
public/index.php
to capture requests with your new class:$response = $kernel->handle(
$request = App\Http\Request::capture()
);
$response->send();
Does this work: yes SideEffects: not known
@colinyoung87 your temproary jQuery solution works perfect, thanks for that!
@mantasradzevicius Thanks. I can confirm this worked after changing the namespace accordingly.
@colinyoung87 Thanks for the solution. This worked perfectly.
Perhaps it can be a Symfony problem. what do you think ?
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An uploaded file must be an array or an instance of UploadedFile.' in /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php:59 Stack trace: #0 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php(73): Symfony\Component\HttpFoundation\FileBag->set('image', NULL) #1 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php(48): Symfony\Component\HttpFoundation\FileBag->add(Array) #2 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php(37): Symfony\Component\HttpFoundation\FileBag->replace(Array) #3 /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Request.php(448): Symfony\Component\HttpFoundation\FileBag->__construct(Array) #4 /var/www/html/.../vendor/laravel/framework/src/Illuminate/Http/Reque in /var/www/html/.../vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/FileBag.php on line 59
FileBag->set('image', NULL), receaves NULL, and that is what is dispatching a throw!
...in Symfony on the FileBag.php file, convertFileInformation method returns NULL if no files was selected on the upload.
+1 @colinyoung87 temporary solution works perfectly!
+1
I have this problem using the multipartGraphQL() when testing the upload of a file! +1
After the recent changes (I did
composer update
a couple of minutes ago) you can't submit a form if you haveenctype="multipart/form-data"
andinput[type="file"]
and leaves the input field empty (no file selected).Link to error message.
1.
2.
3.
Set
debug
totrue
inconfig/app.php
.4.
Open up
app/Providers/RouteServiceProvider.php
and change themap
method to this:5.
Add the following code to
app/Http/HomeController.php
:6.
Change
resources/views/hello.php
to this:If you try to submit the form without selecting a file you will get
Uncaught exception 'InvalidArgumentException' with message 'An uploaded file must be an array or an instance of UploadedFile.'
, but if you select an image, you will get an array fromInput::all()
.Bad (temporary) solution
A solution is to remove an file arrays with a
null
value before using theSymfonyRequest::dublicate
method.Change the content of the
createFromBase
method fromto
You can now submit the form without selecting a file.