Error uploading media files

Created on 18 October 2022, about 2 years ago
Updated 3 June 2024, 6 months ago

Hi, I'm using the latest Drupal 9.4.8 with PHP 8.1.11. If the File Upload Options module is enabled, uploading a media image from "/media/add/image" url returns an error (see below). Uploading an image with the media widget from a node, for example, works fine without any problem.

2022/10/18 10:39:55 [warn] 818#818: *9666 a client request body is buffered to a temporary file /var/cache/nginx/client_temp/0000000013, client: 172.29.0.6, server: , request: "POST /media/add/image?element_parents=field_media_image/widget/0&ajax_form=1&_wrapper_format=drupal_ajax HTTP/1.1", host: "example.ddev.site", referrer: "https://example.ddev.site/media/add/image"
[18-Oct-2022 10:39:55] WARNING: [pool www] child 1228 said into stderr: "NOTICE: PHP message: TypeError: Drupal\file\Upload\FileUploadHandler::handleFileUpload(): Argument #4 ($replace) must be of type int, null given, called in /var/www/html/web/core/modules/file/file.module on line 846 in /var/www/html/web/core/modules/file/src/Upload/FileUploadHandler.php on line 142 #0 /var/www/html/web/core/modules/file/file.module(846): Drupal\file\Upload\FileUploadHandler->handleFileUpload(Object(Drupal\file\Upload\FormUploadedFile), Array, 'public://images...', NULL)"
[18-Oct-2022 10:39:55] WARNING: [pool www] child 1228 said into stderr: "#1 /var/www/html/web/core/modules/file/file.module(722): file_save_upload('field_media_ima...', Array, 'public://images...', NULL, NULL)"
[18-Oct-2022 10:39:55] WARNING: [pool www] child 1228 said into stderr: "#2 /var/www/html/web/modules/contrib/file_upload_options/file_upload_options.module(208): _file_save_upload_from_form(Array, Object(Drupal\Core\Form\FormState), NULL, NULL)"
[18-Oct-2022 10:39:55] WARNING: [pool www] child 1228 said into stderr: "#3 /var/www/html/web/modules/contrib/file_upload_options/src/Services/FileUploadService.php(166): file_upload_options_file_managed_file_save_upload(Array, Object(Drupal\Core\Form\FormState))"
[18-Oct-2022 10:39:55] WARNING: [pool www] child 1228 said into stderr: "#4 /var/www/html/web/module..."
2022/10/18 10:39:55 [error] 818#818: *9666 FastCGI sent in stderr: "PHP message: TypeError: Drupal\file\Upload\FileUploadHandler::handleFileUpload(): Argument #4 ($replace) must be of type int, null given, called in /var/www/html/web/core/modules/file/file.module on line 846 in /var/www/html/web/core/modules/file/src/Upload/FileUploadHandler.php on line 142 #0 /var/www/html/web/core/modules/file/file.module(846): Drupal\file\Upload\FileUploadHandler->handleFileUpload(Object(Drupal\file\Upload\FormUploadedFile), Array, 'public://images...', NULL)
#1 /var/www/html/web/core/modules/file/file.module(722): file_save_upload('field_media_ima...', Array, 'public://images...', NULL, NULL)
#2 /var/www/html/web/modules/contrib/file_upload_options/file_upload_options.module(208): _file_save_upload_from_form(Array, Object(Drupal\Core\Form\FormState), NULL, NULL)
#3 /var/www/html/web/modules/contrib/file_upload_options/src/Services/FileUploadService.php(166): file_upload_options_file_managed_file_save_upload(Array, Object(Drupal\Core\Form\FormState))
#4 /var/www/html/web/module" while reading response header from upstream, client: 172.29.0.6, server: , request: "POST /media/add/image?element_parents=field_media_image/widget/0&ajax_form=1&_wrapper_format=drupal_ajax HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm.sock:", host: "example.ddev.site", referrer: "https://example.ddev.site/media/add/image"
šŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡¹Italy finex

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • šŸ‡¦šŸ‡ŗAustralia imclean Tasmania

    Has anyone else had a chance to review this? Does this solve the problem @FiNeX?

  • Status changed to RTBC 6 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @imclean,

    I'm not sure if this is the problem of @FiNex but I have noticed that after I installed the File Upload Options 8.x-1.x-dev , I get an error when trying to add an image file via /media/add/image, please see my attached file error-found-before-patch.

    Drupal.AjaxErrormessage: "\nAn AJAX HTTP error occurred.\nHTTP Result Code: 500\nDebugging information follows.\nPath: /media/add/image?element_parents=field_media_image/widget/0&ajax_form=1\nStatusText: 500 Service unavailable (with message)\nResponseText: The website encountered an unexpected error. Please try again later.TypeError: Drupal\\file\\Upload\\FileUploadHandler::handleFileUpload(): Argument #4 ($replace) must be of type int, null given, called in /var/www/web/core/modules/file/file.module on line 642 in Drupal\\file\\Upload\\FileUploadHandler->handleFileUpload() (line 157 of core/modules/file/src/Upload/FileUploadHandler.php). file_save_upload('field_media_image_0', Array, 'public://2024-05', NULL, NULL) (Line: 520)\n_file_save_upload_from_form(Array, Object, NULL, NULL) (Line: 224)\nfile_upload_options_file_managed_file_save_upload(Array, Object) (Line: 173)\nDrupal\\file_upload_options\\Services\\FileUploadService::valueCallback(Array, Array, Object) (Line: 144)\nDrupal\\file_upload_options\\Services\\FileUploadService::value(Array, Array, Object)\ncall_user_func_array(Array, Array) (Line: 1268)\nDrupal\\Core\\Form\\FormBuilder->handleInputElement('media_image_add_form', Array, Object) (Line: 1005)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('media_image_add_form', Array, Object) (Line: 579)\nDrupal\\Core\\Form\\FormBuilder->processForm('media_image_add_form', Array, Object) (Line: 325)\nDrupal\\Core\\Form\\FormBuilder->buildForm(Object, Object) (Line: 73)\nDrupal\\Core\\Controller\\FormController->getContentResult(Object, Object) (Line: 39)\nDrupal\\layout_builder\\Controller\\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)\ncall_user_func_array(Array, Array) (Line: 123)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 592)\nDrupal\\Core\\Render\\Renderer->executeInRenderContext(Object, Object) (Line: 121)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 181)\nSymfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object, 1) (Line: 76)\nSymfony\\Component\\HttpKernel\\HttpKernel->handle(Object, 1, 1) (Line: 58)\nDrupal\\Core\\StackMiddleware\\Session->handle(Object, 1, 1) (Line: 48)\nDrupal\\Core\\StackMiddleware\\KernelPreHandle->handle(Object, 1, 1) (Line: 106)\nDrupal\\page_cache\\StackMiddleware\\PageCache->pass(Object, 1, 1) (Line: 85)\nDrupal\\page_cache\\StackMiddleware\\PageCache->handle(Object, 1, 1) (Line: 48)\nDrupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)\nDrupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)\nDrupal\\Core\\StackMiddleware\\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)\nDrupal\\Core\\DrupalKernel->handle(Object) (Line: 19)\n"name: "AjaxError"stack: "Error\n    at http://drupal-org-issues.docksal.site/core/misc/ajax.js?v=10.1.8:196:32\n    at http://drupal-org-issues.docksal.site/core/misc/ajax.js?v=10.1.8:1889:3"[[Prototype]]: Error
        at http://drupal-org-issues.docksal.site/core/misc/ajax.js?v=10.1.8:196:32
        at http://drupal-org-issues.docksal.site/core/misc/ajax.js?v=10.1.8:1889:3

    I then applied @cinarb's patch #19. It was applied smoothly and then I don't encounter the issue afterwards when I tried to add an image file via /media/add/image, please see my attached file image-added-after-patch.

    āžœ  file_upload_options git:(d2b302c) curl https://www.drupal.org/files/issues/2022-10-27/3315976-19.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  4392  100  4392    0     0   9594      0 --:--:-- --:--:-- --:--:--  9589
    patching file file_upload_options.install
    patching file file_upload_options.module
    Hunk #2 succeeded at 279 (offset 16 lines).
    āžœ  file_upload_options git:(d2b302c) āœ—

    I will move the status to Reviewed & tested by the community.

    Thank you.

  • Status changed to Needs review 6 months ago
  • šŸ‡¦šŸ‡ŗAustralia imclean Tasmania

    Thanks @cleavinjosh, I'd liked to hear from @FiNeX as well if possible.

Production build 0.71.5 2024