Skip to content

fix(upload): attachment sharing fails due to chunked upload filecache bug #6153

@IIMacGyverII

Description

@IIMacGyverII

Summary

Sending images/files in Talk chat always fails silently — the upload appears to complete but the file never appears in the conversation for either the sender or recipient.

Steps to Reproduce

  1. Open any Talk conversation
  2. Tap the attachment button and select a photo from the gallery
  3. Observe: no image appears in the chat for sender or recipient; no error is shown

Expected Behavior

The image is uploaded to the Nextcloud files folder and shared into the conversation, appearing as a message attachment.

Actual Behavior

Upload appears to complete (no error notification), but the file never appears in chat. The recipient never receives it.

Root Cause

Nextcloud's chunked upload assembly is broken on affected server versions. When the Android app performs the final WebDAV MOVE from /remote.php/dav/uploads/<user>/<uuid>/.file to /remote.php/dav/files/<user>/Talk/<filename>, the server returns HTTP 201 Created — but silently fails to register the file in its oc_filecache database table.

This means:

  • A subsequent WebDAV HEAD request for the same URL returns 404
  • The OCS sharing API (/ocs/v2.php/apps/files_sharing/api/v1/shares) returns HTTP 404 "Wrong path, file/folder does not exist" when the app tries to share the file into the Talk room

The bug only manifests via chunked upload (used for files > 1 MB in the original code). Direct PUT upload correctly updates the filecache.

Network Traffic

MKCOL /remote.php/dav/uploads/<user>/<uuid>                  → 201
PUT   /remote.php/dav/uploads/<user>/<uuid>/0*               → 201 (all chunks)
MOVE  .../uploads/.../.file → .../files/<user>/Talk/photo.jpg → 201
HEAD  /remote.php/dav/files/<user>/Talk/photo.jpg            → 404  ← not in filecache
POST  /ocs/v2.php/.../shares  path=/Talk/photo.jpg           → 404 "Wrong path"

Fix

Raise the chunked upload threshold from 1 MB to 20 MB in UploadAndShareFilesWorker. Files under 20 MB (covering virtually all phone photos) now use a direct PUT upload which correctly updates the server filecache. Chunked upload is preserved for files over 20 MB.

Additional hardening also included:

  • ChunkedFileUploader: Use a fresh OkHttpClient without OCS-APIRequest: true / Accept: application/json headers — those headers were causing Nextcloud's sabre/dav to return JSON 200 instead of XML 207 Multi-Status for PROPFIND, breaking dav4jvm. PROPFIND errors now fall back gracefully (re-upload all chunks from scratch).
  • FileUploader: Fixed createRequestBody() using available() which returns 0 for content:// URIs; now uses readBytes().
  • ShareOperationWorker: Added retry logic (up to 4 attempts, 2 s apart) on 404 for large files that still go 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions