[Bug]: bucket_name in oc_preview_locations too short
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
⚠️ This issue respects the following points: ⚠️
- This is a bug, not a question or a configuration/webserver/proxy issue.
- This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
- Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- I agree to follow Nextcloud's Code of Conduct.
Bug description
When setting up a new instance using s3 as storage backend, and postgresql as a database, file previews were not working.
During investigation a sql error surfaced.
An exception occurred while executing a query: SQLSTATE[22001]: String data, right truncated: 7 ERROR: value too long for type character varying(40)
After checking the database schema the table oc_preview_locations seeems to store the bucket name in a field of character varying(40).
Changing the field type to allow for longer bucket names fixed the issue:
alter table oc_preview_locations alter column bucket_name type character varying(63)
AWS allows bucket names up to 63 characters in length (https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html) and I'd suggest to apply the same here.
Steps to reproduce
1.Configure nextcloud on postgresql using s3 object storage as primary storage backend with a bucket name longer than 40 characters.
2.Open files app
3.Previews are broken and sql error in log An exception occurred while executing a query: SQLSTATE[22001]: String data, right truncated: 7 ERROR: value too long for type character varying(40)
Expected behavior
No error in log and previews work
Nextcloud Server version
32
Operating system
None
PHP engine version
None
Web server
Apache
Database engine version
Postgresql 17
Is this bug present after an update or on a fresh install?
Fresh install
Are you using the Nextcloud Server Encryption module?
No
What user-backends are you using?
- Default user-backend (database)
- LDAP/ Active Directory
- SSO - SAML
- Other
Configuration report
List of activated Apps
Nextcloud Signing status
Nextcloud Logs
Additional info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the schema definition for the oc_preview_locations table and its bucket_name column, then inspect the related preview-storage entry points and database migration coverage. Reproduce the PostgreSQL failure with an S3 bucket name over 40 characters; done means the schema accepts the supported bucket length and file previews work without the truncation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, php, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100