Skip to content

Uploads hardening#6183

Open
mahibi wants to merge 4 commits into
masterfrom
bugfix/noid/improve-attachment-upload
Open

Uploads hardening#6183
mahibi wants to merge 4 commits into
masterfrom
bugfix/noid/improve-attachment-upload

Conversation

@mahibi
Copy link
Copy Markdown
Collaborator

@mahibi mahibi commented May 12, 2026

branched off from #6152 (thanks for the initial commit to @IIMacGyverII 👍 )

This PR improves attachment upload reliability across both normal and chunked uploads and makes post-upload chat updates more reliable.

What changed

  • make chunked uploads more resilient when the server returns unexpected responses while checking existing chunks
  • ensure remote target folders exist before assembling chunked uploads
  • scope OCS headers to actual OCS endpoints only
  • reuse the shared upload client configuration for upload requests, including auth, SSL and proxy handling
  • trigger an immediate chat refresh after upload/share completion instead of waiting for the next regular polling cycle
  • retry post-upload message fetching when the server-side chat message is not available yet
  • retry media preview loading for transient 5xx server errors
  • keep the chunked upload threshold at 1 MB (other than suggest by @IIMacGyverII to increase it to 20MB) (this is done because for the normal upload there is no upload progress for now. Once there is an upload progress shown also for the normal uploads, it's fine to increase the threshold again)

Why

Uploading attachments could fail or appear delayed in a few different ways:

  • chunked uploads could fail because of server-side/filecache timing issues
  • sharing could fail when the uploaded file was not immediately visible server-side
  • the chat message for the uploaded attachment could show up late because the client missed the first post-upload refresh window
  • media previews could temporarily fail with a server error even though the message itself had already been created

This change makes the whole upload flow more tolerant to these timing-related backend races.

User impact

  • attachment uploads are more reliable
  • uploaded files appear in chat more consistently right after upload
  • transient preview generation failures recover automatically
  • upload behavior is consistent across normal and chunked uploads

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

@mahibi mahibi self-assigned this May 12, 2026
IIMacGyverII and others added 4 commits May 13, 2026 15:07
…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)
Apply OCS-specific headers only for OCS endpoints in the global headers interceptor to avoid affecting DAV requests.
Switch chunked and normal uploaders back to okHttpClient.newBuilder() so they inherit shared client config while keeping upload-specific redirect/protocol/auth settings.
AI-assistant: Copilot 1.8.2-243 (GPT-5-Codex)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Refresh the chat immediately after upload/share completion and retry
message fetches briefly when the server still returns 304.

Also retry media previews on transient 5xx server errors so newly
uploaded images are less likely to stay stuck on a placeholder.

AI-assistant: Copilot 1.8.2-243 (GPT-5-Codex)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
this is done because for the normal upload there is no upload progress for now. Once there is an upload progress shown also for the normal uploads, it's fine to increase the threshold again

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi mahibi force-pushed the bugfix/noid/improve-attachment-upload branch from 4d76ea3 to a020414 Compare May 13, 2026 15:41
@mahibi mahibi changed the title chuncked uploads hardening Uploads hardening May 13, 2026
@mahibi mahibi added this to the 24.0.0 milestone May 13, 2026
@mahibi mahibi added the 3. to review Waiting for reviews label May 13, 2026
@mahibi mahibi marked this pull request as ready for review May 13, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants