fix(upload): fix attachment sharing failure due to chunked upload filecache bug#6152
Conversation
…oad filecache bug Files sent as chat attachments never appeared in the conversation. Investigation showed the chunked upload MOVE returned HTTP 201 but a subsequent HEAD on the assembled file returned 404 - Nextcloud's server was not registering the file in oc_filecache on assembly. The OCS sharing API uses the filecache, so it also returned 404 'Wrong path, file/folder does not exist' despite the file existing on disk. Raise the chunked upload threshold from 1 MB to 20 MB so that typical phone photos go through direct PUT upload, which correctly updates the filecache. Chunked upload is still used for files over 20 MB. Additional fixes: - ChunkedFileUploader: build a fresh OkHttpClient without OCS-APIRequest and Accept: application/json headers, which were causing sabre/dav to return JSON 200 instead of XML 207 for PROPFIND, breaking dav4jvm. PROPFIND failures now fall back gracefully to uploading all chunks fresh. - FileUploader: fix createRequestBody() to use readBytes() instead of available(), which returns 0 for content:// URIs. - ShareOperationWorker: retry share creation up to 4 times with 2s delay on 404, as a safety net for large files using chunked upload. Signed-off-by: IIMacGyverII <macgyverjunk@yahoo.com> AI-assistant: Copilot 0.45.1 (Claude Sonnet 4.6)
|
Just to clairfy, this bug has been preventing me from uploading photos or files on my android devices to other Nextcloud Talk apps and the web browser for years across multiple server installs. I was never able to figure it out until now. iOS and the web browser with Nextcloud Talk always worked fine but android never worked for me. This fixes it. |
|
We are now trying to catch up with the pull request reviews. The PR is not forgotten and should be picked up soon. |
|
Thank you @IIMacGyverII 👍 While reviewing i stumbled over some more things regarding the uploads and also needed to rebase on latest master ...so this led to the fact that i branched off and put more changes on top of your PR. Thank you for contributing! |
|
Completely fine with me! Thanks! |
Summary
Sending images/files in Talk chat silently fails — the upload completes but the file never appears in the conversation for either the sender or recipient. This affects all self-hosted Nextcloud servers and has been reported across multiple server versions.
Steps to Reproduce
Expected Behavior
The image is uploaded to Nextcloud files and shared into the conversation as a message attachment.
Actual Behavior
The upload silently succeeds internally but the file never appears in chat for sender or recipient.
Root Cause
Nextcloud's chunked upload assembly is broken on affected server versions. The final WebDAV
MOVE(from/remote.php/dav/uploads/<user>/<uuid>/.fileto/remote.php/dav/files/<user>/Talk/<filename>) returns HTTP 201 Created, but the server silently fails to register the file in itsoc_filecachedatabase. AHEADrequest immediately after the "successful" MOVE returns 404 — the file doesn't exist as far as Nextcloud's APIs are concerned.When the app then calls the OCS sharing API to share the file into the Talk room, it gets:
The bug only manifests via chunked upload. Direct
PUTupload correctly updates the filecache.Network trace confirming the issue:
Fix
Raise
CHUNK_UPLOAD_THRESHOLD_SIZEfrom 1 MB to 20 MB inUploadAndShareFilesWorker. Files under 20 MB (virtually all phone photos) now go through directPUTupload, which correctly updates the filecache. Chunked upload is preserved for files over 20 MB.Additional hardening:
ChunkedFileUploader: Build a freshOkHttpClientthat does not inheritOCS-APIRequest: true/Accept: application/jsonfrom the app's singleton client. Those headers were causing sabre/dav to return JSON200instead of XML207 Multi-StatusforPROPFIND, breaking dav4jvm.PROPFINDfailures now fall back gracefully to re-uploading all chunks.FileUploader: FixcreateRequestBody()to usereadBytes()instead ofavailable(), which returns 0 forcontent://URIs and caused the PUT body to be empty.ShareOperationWorker: Retry share creation up to 4 times with a 2 s delay on 404, as a safety net for large files still going through chunked upload.Affected Versions
Reproducible on self-hosted Nextcloud regardless of server version (confirmed on multiple servers). iOS and web Talk clients are not affected because they do not use chunked upload for typical-sized attachments.
🖼️ Screenshots
Not applicable — the fix is upload/share logic with no UI changes.
🏁 Checklist
/backport to stable-xx.x