vanilophp / framework

The truly Laravel E-commerce Framework
https://vanilo.io
MIT License
810 stars 102 forks source link

MediaCreate has no file size limit #80

Closed S-DICKSON closed 4 years ago

S-DICKSON commented 4 years ago

Hi, there seems to be no limit on the image upload. Please have a look at my test below where I send a request of a 5gb image and the request is accepted and stores it.

https://github.com/vanilophp/framework/blob/5f5ec185c9afe4c1023c6213314cad31b616595f/src/Http/Requests/CreateMedia.php#L31

    $product = app(Product::class)::create(['name' => 'Product 1']);
    $this->assertNull($product->getFirstMedia());

    $postData = [
        'for' => "product",
        'forId' => $product->id,
        '_token' => csrf_token(),
        'images' => UploadedFile::fake()->image('product.jpg')->size(5000000)
    ];

    $this->post(route("vanilo.media.store"), $postData)->assertStatus(302);

    $this->assertNull($product->refresh()->getFirstMedia());
fulopattila122 commented 4 years ago

You can use media collections to restrict file sizes: https://docs.spatie.be/laravel-medialibrary/v7/working-with-media-collections/defining-media-collections/#only-allow-certain-files-in-a-collection

See also spatie/laravel-medialibrary#1643

j-dohnalek commented 4 years ago

Hello, that link returns 404. image

Is there any specific reason you can not restrict the image size in form request?
https://laravel.com/docs/6.x/validation#rule-size

fulopattila122 commented 4 years ago

https://github.com/spatie/laravel-medialibrary/issues/1643

https://docs.spatie.be/laravel-medialibrary/v8/working-with-media-collections/defining-media-collections/#only-allow-certain-files-in-a-collection

You can also restrict the file size in the form request if you prefer so: https://vanilo.io/docs/1.2/form-requests#customizing-form-requests