After a while: Error Loading <filename>

Nextcloud version (eg, 20.0.5): 20.0.14.2
Operating system and version (eg, Ubuntu 20.04): Linux 2.6.32-754.27.1.el6.x86_64
Apache or nginx version (eg, Apache 2.4.25): unknown
PHP version (eg, 7.4): 7.2

Hello,

I installed Nextcloud mainly for hosting picture files.
However after a while (which can be immediately after upload) I cannot access some of the uploaded files any more. First of all, the preview icon of such a file is grayed out and when I click on it then I get: “Error Loading filename”.

I cannot see any rule on what files are affected.
The picture files themselves on the server are still ok so I guess it has something to do with preview files which get corrupted - or deleted.

My installation is within a webspace environment of the German Provider Netcup.
It has some limitations, amoung others PHP limits.
Could it be that those limits are causing my troubles?

I am running the Nextcloud cron job “cron.php” every 15 minutes.
Could that harm preview files? Maybe if it gets aborted after reaching some PHP limit?

Is there a workaround in this case if there isn’t a solution?
For instance disabling that cron job?
How can I manually re-create the missing preview files?

Steps to replicate it:
Not really any because it happens on a random basis.

The output of your Nextcloud log in Admin > Logging:

nothing appropriate

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

?php
$CONFIG = array (
  'instanceid' => 'XXX',
  'passwordsalt' => 'XXX',
  'secret' => 'XXX',
  'trusted_domains' =>
  array (
    0 => 'XXX',
  ),
  /**
  * 'datadirectory' => '/var/www/vhosts/some-dirs-in-between/nextcloud/data',
  */
  'datadirectory' => ((php_sapi_name() != 'cli') ? '/var/www/vhosts/XXX' : '').'XXX/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '20.0.14.2',
  'overwrite.cli.url' => 'https://XXX/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => '<my IP>:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'cloud',
  'dbpassword' => 'XXX',
  'installed' => true,

The output of your Apache/nginx/system log in /var/log/____:

nothing of relevance

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

{"reqId":"5rR3UTM9dYOZfLDXQ2WQ",
	"level":3,
	"time":"2022-08-21T06:45:03+00:00",
	"remoteAddr":"xx.xx.xx.xx",
	"user":"Me",
	"app":"PHP",
	"method":"GET",
	"url":"/nextcloud/index.php/core/preview?fileId=5352&x=1920&y=1080&a=true",
	"message":{"Exception":"Error",
				"Message":"file_put_contents(/var/www/vhosts/some-dirs-in-between/nextcloud/data/appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg): failed to open stream: No such file or directory at /var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/Storage/Local.php#283",
				"Code":0,
				"Trace":[{"function":"onError",
							"class":"OC\\Log\\ErrorHandler",
							"type":"::",
							"args":[2,
									"file_put_contents(/var/www/vhosts/some-dirs-in-between/nextcloud/data/appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg): failed to open stream: No such file or directory",
									"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/Storage/Local.php",
									283,
									{"path":"appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg",
										"data":null,
										"oldMask":18
									}
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/Storage/Local.php",
						 	"line":283,
							"function":"file_put_contents",
							"args":["/var/www/vhosts/some-dirs-in-between/nextcloud/data/appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg",
									null
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php",
						 	"line":257,
							"function":"file_put_contents",
							"class":"OC\\Files\\Storage\\Local",
							"type":"->",
							"args":["appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg",
									null
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/View.php",
						 	"line":1165,
						 	"function":"file_put_contents",
							"class":"OC\\Files\\Storage\\Wrapper\\Wrapper",
							"type":"->",
							"args":["appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg",
									null
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/View.php",
						 	"line":702,
							"function":"basicOperation",
							"class":"OC\\Files\\View",
							"type":"->",
							"args":["file_put_contents",
									"/appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg",
									["create","write"],
									null
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/Node/Folder.php",
						 	"line":200,
							"function":"file_put_contents",
							"class":"OC\\Files\\View",
							"type":"->",
							"args":["/appdata_oc20caq6lkb1/preview/7/2/6/1/9/2/5/5352/1920-1440-max.jpg",
									null
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Files/SimpleFS/NewSimpleFile.php",
						 	"line":133,
							"function":"newFile",
							"class":"OC\\Files\\Node\\Folder",
							"type":"->",
							"args":["1920-1440-max.jpg",
									null]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Preview/Generator.php",
						 	"line":262,
							"function":"putContent",
							"class":"OC\\Files\\SimpleFS\\NewSimpleFile",
							"type":"->",
							"args":[null]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Preview/Generator.php",
						 	"line":140,
							"function":"getMaxPreview",
							"class":"OC\\Preview\\Generator",
							"type":"->",
							"args":[{"__class__":"OC\\Files\\SimpleFS\\SimpleFolder"},
									{"__class__":"OC\\Files\\SimpleFS\\NewSimpleFile"},
									"image/jpeg",
									""
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Preview/Generator.php",
						 	"line":109,
							"function":"generatePreviews",
							"class":"OC\\Preview\\Generator",
							"type":"->",
							"args":[{"__class__":"OC\\Files\\Node\\File"},
									[{"width":1920,"height":1080,"crop":false,"mode":"fill"}],
									"image/jpeg"
								   ]
						 },
						 {"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/PreviewManager.php",
						 	"line":190,
							"function":"getPreview",
							"class":"OC\\Preview\\Generator",
							"type":"->",
							"args":[{"__class__":"OC\\Files\\Node\\File"},1920,1080,false,"fill",null]},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/core/Controller/PreviewController.php",
								"line":170,
								"function":"getPreview",
								"class":"OC\\PreviewManager",
								"type":"->",
								"args":[{"__class__":"OC\\Files\\Node\\File"},
											1920,1080,false,"fill"
									   ]
							},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/core/Controller/PreviewController.php",
								"line":143,
								"function":"fetchPreview",
								"class":"OC\\Core\\Controller\\PreviewController",
								"type":"->",
								"args":[{"__class__":"OC\\Files\\Node\\File"},
											1920,1080,true,true,"fill"
									   ]
							},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
								"line":169,
								"function":"getPreviewByFileId",
								"class":"OC\\Core\\Controller\\PreviewController",
								"type":"->",
								"args":[5352,1920,1080,true,true,"fill"]
							},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/AppFramework/Http/Dispatcher.php",
								"line":100,
								"function":"executeController",
								"class":"OC\\AppFramework\\Http\\Dispatcher",
								"type":"->",
								"args":[{"__class__":"OC\\Core\\Controller\\PreviewController"},"getPreviewByFileId"]
							},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/AppFramework/App.php",
								"line":152,
								"function":"dispatch",
								"class":"OC\\AppFramework\\Http\\Dispatcher",
								"type":"->",
								"args":[{"__class__":"OC\\Core\\Controller\\PreviewController"},"getPreviewByFileId"]
							},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Route/Router.php",
								"line":309,
								"function":"main",
								"class":"OC\\AppFramework\\App",
								"type":"::",
								"args":["OC\\Core\\Controller\\PreviewController",
										"getPreviewByFileId",
										{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},
										{"_route":"core.Preview.getPreviewByFileId"}
									   ]
							},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/base.php",
								"line":1008,
								"function":"match",
								"class":"OC\\Route\\Router",
								"type":"->",
								"args":["/core/preview"]
							},
							{"file":"/var/www/vhosts/some-dirs-in-between/nextcloud/index.php",
								"line":37,
								"function":"handleRequest",
								"class":"OC",
								"type":"::",
								"args":[]
							}
						],
				"File":"/var/www/vhosts/some-dirs-in-between/nextcloud/lib/private/Log/ErrorHandler.php",
				"Line":91,
				"CustomMessage":"--"
			},
	"userAgent":"Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0",
	"version":"20.0.14.2"
}