Skip to content

fix(PublicPreview): Call getMimetype() on File objects#56196

Open
solracsf wants to merge 1 commit into
masterfrom
callPreviewOnFile
Open

fix(PublicPreview): Call getMimetype() on File objects#56196
solracsf wants to merge 1 commit into
masterfrom
callPreviewOnFile

Conversation

@solracsf

@solracsf solracsf commented Nov 4, 2025

Copy link
Copy Markdown
Member

Summary

The broad try-catch block catches NotFoundException from multiple points: $share->getNode(), $node->get($file), or previewManager->getPreview().

If the exception occurs before $file is reassigned to a valid \OCP\Files\File object (e.g., during $node->get($file)), $file remains the original string parameter.

The catch block then attempts $file->getMimeType(), causing "Call to a member function getMimeType() on string".

Error stack
{
  "reqId": "OYwlO7qQFhBGGteXcWwU",
  "level": 3,
  "time": "2025-11-04T15:26:56+01:00",
  "remoteAddr": "19.24.6.97",
  "user": "--",
  "app": "index",
  "method": "GET",
  "url": "/apps/files_sharing/publicpreview/rNrMYxDyDcyHo4i?file=%2F2025%2F11-Novembre+2025_PSL%2FVarles+pa+du+ms+PSL%2F3.+Abses%2FBORG+-+Arr%C3%AAt+du+0211+au+0411.jpeg&x=32&y=32&mimeFallback=true&v=382f42&a=0",
  "message": "Call to a member function getMimeType() on string in file '/var/www/nextcloud/apps/files_sharing/lib/Controller/PublicPreviewController.php' line 135",
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0",
  "version": "31.0.10.2",
  "exception": {
    "Exception": "Exception",
    "Message": "Call to a member function getMimeType() on string in file '/var/www/nextcloud/apps/files_sharing/lib/Controller/PublicPreviewController.php' line 135",
    "Code": 0,
    "Trace": [
      {
        "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
        "line": 161,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          {
            "__class__": "OCA\\Files_Sharing\\Controller\\PublicPreviewController"
          },
          "getPreview"
        ]
      },
      {
        "file": "/var/www/nextcloud/lib/private/Route/Router.php",
        "line": 315,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\Files_Sharing\\Controller\\PublicPreviewController",
          "getPreview",
          {
            "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
          },
          {
            "token": "rNrMYxDyDcyHo4i",
            "_route": "files_sharing.publicpreview.getpreview"
          }
        ]
      },
      {
        "file": "/var/www/nextcloud/lib/base.php",
        "line": 1063,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->",
        "args": [
          "/apps/files_sharing/publicpreview/rNrMYxDyDcyHo4i"
        ]
      },
      {
        "file": "/var/www/nextcloud/index.php",
        "line": 24,
        "function": "handleRequest",
        "class": "OC",
        "type": "::",
        "args": []
      }
    ],
    "File": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
    "Line": 146,
    "Previous": {
      "Exception": "Error",
      "Message": "Call to a member function getMimeType() on string",
      "Code": 0,
      "Trace": [
        {
          "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 200,
          "function": "getPreview",
          "class": "OCA\\Files_Sharing\\Controller\\PublicPreviewController",
          "type": "->",
          "args": [
            "rNrMYxDyDcyHo4i",
            "/2025/11-Novembre 2025_PSL/Variables paie du mois PSL/3. Absences/BORGES - Arrêt du 0211 au 0411.jpeg",
            32,
            32,
            false,
            true
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
          "line": 114,
          "function": "executeController",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->",
          "args": [
            {
              "__class__": "OCA\\Files_Sharing\\Controller\\PublicPreviewController"
            },
            "getPreview"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/AppFramework/App.php",
          "line": 161,
          "function": "dispatch",
          "class": "OC\\AppFramework\\Http\\Dispatcher",
          "type": "->",
          "args": [
            {
              "__class__": "OCA\\Files_Sharing\\Controller\\PublicPreviewController"
            },
            "getPreview"
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/private/Route/Router.php",
          "line": 315,
          "function": "main",
          "class": "OC\\AppFramework\\App",
          "type": "::",
          "args": [
            "OCA\\Files_Sharing\\Controller\\PublicPreviewController",
            "getPreview",
            {
              "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
            },
            {
              "token": "rNrMYxDyDcyHo4i",
              "_route": "files_sharing.publicpreview.getpreview"
            }
          ]
        },
        {
          "file": "/var/www/nextcloud/lib/base.php",
          "line": 1063,
          "function": "match",
          "class": "OC\\Route\\Router",
          "type": "->",
          "args": [
            "/apps/files_sharing/publicpreview/rNrMYxDyDcyHo4i"
          ]
        },
        {
          "file": "/var/www/nextcloud/index.php",
          "line": 24,
          "function": "handleRequest",
          "class": "OC",
          "type": "::",
          "args": []
        }
      ],
      "File": "/var/www/nextcloud/apps/files_sharing/lib/Controller/PublicPreviewController.php",
      "Line": 135
    },
    "message": "Call to a member function getMimeType() on string in file '/var/www/nextcloud/apps/files_sharing/lib/Controller/PublicPreviewController.php' line 135",
    "exception": [],
    "CustomMessage": "Call to a member function getMimeType() on string in file '/var/www/nextcloud/apps/files_sharing/lib/Controller/PublicPreviewController.php' line 135"
  },
  "id": "690a30525b5c6"
}

Checklist

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf solracsf added this to the Nextcloud 33 milestone Nov 4, 2025
@solracsf solracsf requested a review from a team as a code owner November 4, 2025 17:40
@solracsf solracsf requested review from Altahrim, ArtificialOwl, CarlSchwan and yemkareems and removed request for a team November 4, 2025 17:40
@solracsf

Copy link
Copy Markdown
Member Author

/backport to stable32

@solracsf

Copy link
Copy Markdown
Member Author

/backport to stable31

@solracsf solracsf enabled auto-merge December 18, 2025 10:07
This was referenced Jan 7, 2026
This was referenced Jan 14, 2026
This was referenced Jan 29, 2026
This was referenced Feb 11, 2026
@blizzz blizzz modified the milestones: Nextcloud 33, Nextcloud 34 Feb 16, 2026
This was referenced Jun 5, 2026
@susnux susnux added the community pull requests from community label Jun 9, 2026
@susnux susnux removed this from the Nextcloud 34.0.1 milestone Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants