Skip to content

[RichDocuments] downloadAs JSON key mismatch - file download fails with Collabora Online #4114

@chrip

Description

@chrip

Bug Description

When downloading/exporting documents from Collabora Online (richdocuments) in the Nextcloud iOS app, the downloadAs JavaScript interface fails to parse the JSON message due to a key name mismatch between the JavaScript side and the iOS side.

Root Cause

JavaScript side (Collabora Online mobile.js wraps the message):

{
  "MessageName": "downloadAs",
  "Values": {
    "url": "https://...",
    "format": "pdf"
  }
}

iOS side (NCViewerRichDocument.swift:138-140) expects:

guard let type = values["Type"] as? String else { return }
guard let urlString = values["URL"] as? String else { return }

The iOS code uses uppercase keys ("Type", "URL") which don't match what Collabora Online sends ("format", "url"). The guard let statements silently return, causing all downloads to fail.

Affected Code

  • iOSClient/Viewer/NCViewerRichdocument/NCViewerRichDocument.swift - userContentController(_:didReceive:) method, downloadAs handling block (lines ~135-180)

Reproduction Steps

  1. Open a document in Collabora Online via the Nextcloud iOS app
  2. Tap "Export as PDF" (or any other export/download format)
  3. The download silently does nothing

Expected Behavior

The file should download and present the share/export options sheet.

Proposed Fix

Update userContentController to handle both key naming conventions:

if let values = param["Values"] as? [AnyHashable: Any] {
    // Support both old ("Type"/"URL") and new ("format"/"url") key formats
    let type = values["Type"] as? String ?? values["format"] as? String
    let urlString = values["URL"] as? String ?? values["url"] as? String
    guard let type = type, let urlString = urlString else { return }
    guard let url = URL(string: urlString) else { return }
    // ... rest of the logic
}

Related

Metadata

Metadata

Assignees

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