magento2: Fail to upload image on configurable returns "alert("true")"

Summary of the issue (*)

An alert saying true is displayed when trying to upload a large image in one of the configurable options created under Configurations section, when creating a new configurable product.

Preconditions (*)

  1. Magento 2.3.2 Open Source, Production mode. Also reproducible on 2.4-develop in Default mode
  2. Nginx/1.14.0 (Ubuntu)
  3. PHP 7.1.30
  4. Opcache v. 7.1.30
  5. Ubuntu 18.04.1 on Digital Ocean
  6. Redis v.4.0.9
  7. Vanilla Magento with sample data deployed, installed via composer
  8. SSL Enabled via certbot / Lets encrypt

Steps to reproduce (*)

  1. Start creating new configurable product

  2. In the Configurations section, click on Create Configurations and generate some products. I created 2 just for this example.

  3. Click on the + icon to add a photo on the first product New_Product___Products___Inventory___Catalog___Magento_Admin

  4. Select a large file (in my case, 11 Mb was enough) and try to upload it. You can use this one if you want.

Expected result (*)

  1. Some warning saying the file is too big to my configuration or see the uploaded image. The same file can be uploaded when editing/creating a simple product.

Actual result (*)

  1. I got a alert saying “True”. image

  2. The ajax request to /mageadmin/catalog/product_gallery/upload/key/…/?isAjax=true brings a wrong error: {"error":true,"message":"Invalid Form Key. Please refresh the page."}, which is not true, as I can navigate to other pages in the admin.

  3. Nginx error log shows:

==> /var/log/nginx/error.log <== 2019/08/13 19:38:20 [error] 5288#5288: *4759 FastCGI sent in stderr: “PHP message: PHP Warning: POST Content-Length of 13816642 bytes exceeds the limit of 8388608 bytes in Unknown on line 0” while reading response header from upstream, client: 103.217.166.165, server: magento2.magenteiro.com, request: “POST /mageadmin/catalog/product_gallery/upload/key/c2ce4a909e2fc7442d229ee38953ad5e82c015b2db68086fc2a7b1514451cc67/?isAjax=true HTTP/2.0”, upstream: “fastcgi://unix:/run/php/php7.1-fpm.sock:”, host: “magento2.magenteiro.com”, referrer: "https://magento2.magenteiro.com/mageadmin/catalog/product/new/set/4/type/configurable/key/e3879da6ef8893c356e2cc9d0b854b81e30f10005f7fbeed6883d908eb76b6ab/

  1. If I upload the same image when editing a simple product, I have no errors.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 32 (22 by maintainers)

Most upvoted comments

This issue is caused by POST payload larger than post_max_size for PHP. This causes to truncate POST data and also Form Key is truncated. Missing Form Key executes the exception that it is missing and JSON response that is not compatible with the current implementation of javascript uploader: The response is: {“error”:true,“message”:“Invalid Form Key. Please refresh the page.”} while JS Uploader expects error as humar readable string on “error” field. For that reason here it shows Alert with “true” as this is the value of the field.

To fix that somebody would have to either add proper handling to js uploader - but this will be like halfway solution as it will output error of “Invalid Form Key. Please refresh the page.” - this is also misleading. Or implement a file size validator before the file is uploaded, and set the limit based on max_post_data value in PHP settings.