I recently cleared my previews because I migrated from a physical instance of nextcloud to a docker instance. Cleaning previews and re-generating made more sense since it reduced the amount of files to transfer and reduce issues in differences in versions.
Because the database still contains an entry for the file I'm trying to view, but the generated preview does not, next cloud throws a stack trace and returns back an error image for the file we are attempting to view the preview of.
The database shouldn't contain any entries and there should be no previews for the file in the file system, so the preview is generated. If there is a database entry, but the file doesn't exist, the preview should be re-generated and the database entry updated.
{"reqId":"jCnAtSZx0A1THfR2XCAM","level":3,"time":"2026-07-27T16:12:52+00:00","remoteAddr":"192.168.50.1","user":"Russell.Weber","app":"index","method":"GET","url":"/apps/photos/api/v1/preview/4258526?etag=d916a3ed5528e0c7695663c41716bbdd&x=1024&y=1024","scriptName":"/index.php","message":"Unable to open preview stream at /var/www/html/data/appdata_ocrlqm104gs0/preview/e/1/7/3/9/e/7/4258526/683-1024.jpg","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:152.0) Gecko/20100101 Firefox/152.0","version":"34.0.2.1","exception":{"Exception":"OCP\\Files\\NotFoundException","Message":"Unable to open preview stream at /var/www/html/data/appdata_ocrlqm104gs0/preview/e/1/7/3/9/e/7/4258526/683-1024.jpg","Code":0,"Trace":[{"file":"/var/www/html/lib/private/Preview/Storage/StorageFactory.php","line":33,"function":"readPreview","class":"OC\\Preview\\Storage\\LocalPreviewStorage","type":"->","args":[{"__class__":"OC\\Preview\\Db\\Preview","id":"64675969711423489"}]},{"file":"/var/www/html/lib/private/Preview/Storage/PreviewFile.php","line":74,"function":"readPreview","class":"OC\\Preview\\Storage\\StorageFactory","type":"->","args":[{"__class__":"OC\\Preview\\Db\\Preview","id":"64675969711423489"}]},{"file":"/var/www/html/lib/public/AppFramework/Http/FileDisplayResponse.php","line":53,"function":"read","class":"OC\\Preview\\Storage\\PreviewFile","type":"->","args":[]},{"file":"/var/www/html/lib/private/AppFramework/App.php","line":194,"function":"callback","class":"OCP\\AppFramework\\Http\\FileDisplayResponse","type":"->","args":[{"__class__":"OC\\AppFramework\\Http\\Output"}]},{"file":"/var/www/html/lib/private/Route/Router.php","line":324,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Photos\\Controller\\PreviewController","index",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"photos.preview.index","fileId":"4258526"}]},{"file":"/var/www/html/lib/base.php","line":1172,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/apps/photos/api/v1/preview/4258526"]},{"file":"/var/www/html/index.php","line":25,"function":"handleRequest","class":"OC","type":"::","args":[]}],"File":"/var/www/html/lib/private/Preview/Storage/LocalPreviewStorage.php","Line":60,"message":"Unable to open preview stream at /var/www/html/data/appdata_ocrlqm104gs0/preview/e/1/7/3/9/e/7/4258526/683-1024.jpg","exception":"{\"class\":\"OCP\\Files\\NotFoundException\",\"message\":\"Unable to open preview stream at /var/www/html/data/appdata_ocrlqm104gs0/preview/e/1/7/3/9/e/7/4258526/683-1024.jpg\",\"code\":0,\"file\":\"/var/www/html/lib/private/Preview/Storage/LocalPreviewStorage.php:60\",\"trace\":\"#0 /var/www/html/lib/private/Preview/Storage/StorageFactory.php(33): OC\\Preview\\Storage\\LocalPreviewStorage->readPreview(Object(OC\\Preview\\Db\\Preview))\\n#1 /var/www/html/lib/private/Preview/Storage/PreviewFile.php(74): OC\\Preview\\Storage\\StorageFactory->readPreview(Object(OC\\Preview\\Db\\Preview))\\n#2 /var/www/html/lib/public/AppFramework/Http/FileDisplayResponse.php(53): OC\\Preview\\Storage\\PreviewFile->read()\\n#3 /var/www/html/lib/private/AppFramework/App.php(194): OCP\\AppFramework\\Http\\FileDisplayResponse->callback(Object(OC\\AppFramework\\Http\\Output))\\n#4 /var/www/html/lib/private/Route/Router.php(324): OC\\AppFramework\\App::main('OCA\\\\Photos\\\\Cont...', 'index', Object(OC\\AppFramework\\DependencyInjection\\DIContainer), Array)\\n#5 /var/www/html/lib/base.php(1172): OC\\Route\\Router->match('/apps/photos/ap...')\\n#6 /var/www/html/index.php(25): OC::handleRequest()\\n#7 {main}\"}","CustomMessage":"Unable to open preview stream at /var/www/html/data/appdata_ocrlqm104gs0/preview/e/1/7/3/9/e/7/4258526/683-1024.jpg"}}
{"reqId":"jCnAtSZx0A1THfR2XCAM","level":2,"time":"2026-07-27T16:12:52+00:00","remoteAddr":"192.168.50.1","user":"Russell.Weber","app":"PHP","method":"GET","url":"/apps/photos/api/v1/preview/4258526?etag=d916a3ed5528e0c7695663c41716bbdd&x=1024&y=1024","scriptName":"/index.php","message":"http_response_code(): Calling http_response_code() after header('HTTP/...') has no effect at /var/www/html/lib/private/Template/TemplateManager.php#118","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:152.0) Gecko/20100101 Firefox/152.0","version":"34.0.2.1","data":{"app":"PHP"}}
However, even after cleaning the preview, there are entries for this file in the database.
id | file_id | storage_id | old_file_id | location_id | width | height | mimetype_id | source_mimetype_id | max | cropped | encrypted | etag | mtime | size | version_id
-------------------+---------+------------+-------------+-------------+-------+--------+-------------+--------------------+-----+---------+-----------+------------------------------------------+------------+--------+------------
64675966586667009 | 4258526 | 9 | | | 2730 | 4096 | 15 | 15 | t | f | f | d916a3ed5528e0c7695663c41716bbdd | 1774335346 | 970645 | -1
64675969711423489 | 4258526 | 9 | | | 683 | 1024 | 15 | 15 | f | f | f | d916a3ed5528e0c7695663c41716bbdd | 1774335347 | 89540 | -1
(2 rows)
Nextcloud configuration
root@dungeon[~]# ./occ config:list system
{
"system": {
"htaccess.RewriteBase": "\/",
"memcache.local": "\\OC\\Memcache\\APCu",
"apps_paths": [
{
"path": "\/var\/www\/html\/apps",
"url": "\/apps",
"writable": false
},
{
"path": "\/var\/www\/html\/custom_apps",
"url": "\/custom_apps",
"writable": true
}
],
"memcache.distributed": "\\OC\\Memcache\\Redis",
"memcache.locking": "\\OC\\Memcache\\Redis",
"redis": {
"host": "***REMOVED SENSITIVE VALUE***",
"password": "***REMOVED SENSITIVE VALUE***",
"port": 6379
},
"trusted_proxies": "***REMOVED SENSITIVE VALUE***",
"upgrade.disable-web": true,
"passwordsalt": "***REMOVED SENSITIVE VALUE***",
"secret": "***REMOVED SENSITIVE VALUE***",
"datadirectory": "***REMOVED SENSITIVE VALUE***",
"dbtype": "pgsql",
"version": "34.0.2.1",
"dbname": "***REMOVED SENSITIVE VALUE***",
"dbhost": "***REMOVED SENSITIVE VALUE***",
"dbport": "",
"dbtableprefix": "oc_",
"dbuser": "***REMOVED SENSITIVE VALUE***",
"dbpassword": "***REMOVED SENSITIVE VALUE***",
"installed": true,
"instanceid": "***REMOVED SENSITIVE VALUE***",
"serverid": "ocrlqm104gs1",
"preview_max_memory": -1,
"loglevel": 2,
"maintenance": false,
"data-fingerprint": "f6de0f345fac337c7fafd2a65bd245a5",
"overwritehost": "cloud.weberbia.ninja",
"overwriteprotocol": "https",
"overwrite.cli.url": "https:\/\/cloud.weberbia.ninja",
"default_phone_region": "US",
"maintenance_window_start": 1,
"mail_smtpmode": "smtp",
"mail_smtphost": "***REMOVED SENSITIVE VALUE***",
"mail_sendmailmode": "smtp",
"mail_smtpport": "587",
"mail_smtpauth": true,
"mail_from_address": "***REMOVED SENSITIVE VALUE***",
"mail_domain": "***REMOVED SENSITIVE VALUE***",
"mail_smtpname": "***REMOVED SENSITIVE VALUE***",
"mail_smtppassword": "***REMOVED SENSITIVE VALUE***",
"preview_imaginary_url": "***REMOVED SENSITIVE VALUE***",
"trusted_domains": [
"127.0.0.1",
"192.168.50.2",
"cloud.weberbia.ninja",
"dungeon.weberbia.ninja",
"dungeon.weberbia.ninja:3000",
"localhost",
"nextcloud",
"nextcloud.weberbia.ninja",
"nginx"
]
}
}
How to use GitHub
I recently cleared my previews because I migrated from a physical instance of nextcloud to a docker instance. Cleaning previews and re-generating made more sense since it reduced the amount of files to transfer and reduce issues in differences in versions.
Steps to reproduce
Because the database still contains an entry for the file I'm trying to view, but the generated preview does not, next cloud throws a stack trace and returns back an error image for the file we are attempting to view the preview of.
I'm testing a manual workaround right now
Expected behaviour
The database shouldn't contain any entries and there should be no previews for the file in the file system, so the preview is generated. If there is a database entry, but the file doesn't exist, the preview should be re-generated and the database entry updated.
Actual behaviour
GUI returns a 500 and the log reports back an error
However, even after cleaning the preview, there are entries for this file in the database.
Server configuration
Web server: Apache
Database: PostgreSQL
PHP version: 8.5.8
Nextcloud version: 34.0.2
List of activated apps
Nextcloud configuration
Browser
Browser name: ALL
Browser version: ALL
Operating system: Ubuntu
Browser log