Skip to content

Conversation

@GovardhaneNitin
Copy link

  • Removed doctype, docname, frm parameters causing 400 errors
  • Removed conditional check for this.frm
  • Use standalone file upload pattern for wiki attachments
  • Fixes: Error when uploading a file Error when uploading a file #449

…449

- Removed doctype, docname, frm parameters causing 400 errors
- Removed conditional check for this.frm
- Use standalone file upload pattern for wiki attachments
- Fixes: Error when uploading a file #449
Copilot AI review requested due to automatic review settings December 4, 2025 10:32
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #449 by correcting the uploadMedia() function implementation in the wiki editor. The function was attempting to pass undefined parameters (doctype, docname, frm) to frappe.ui.FileUploader, which resulted in 400 errors during file uploads. Since uploadMedia is a standalone function rather than a class method, these this.* references were undefined. The fix removes these parameters and adopts a standalone file upload pattern appropriate for wiki attachments.

Key Changes:

  • Removed undefined parameter references (this.doctype, this.docname, this.frm) from FileUploader configuration
  • Removed conditional check for this.frm in the success callback
  • Applied Prettier formatting changes (trailing comma removals)
Comments suppressed due to low confidence (1)

wiki/public/js/editor.js:377

  • The file upload functionality (including drag-and-drop, paste, and the image/video buttons) lacks test coverage. Consider adding Cypress e2e tests to verify:
  1. File upload via drag-and-drop on the editor
  2. File upload via paste
  3. File upload via the image/video buttons
  4. Proper insertion of markdown/HTML for uploaded files
  5. Validation of allowed file types

This would help prevent regressions like issue #449 in the future.

function uploadMedia(fileTypes, dialogTitle, files = null) {
  // Fixed issue #449: Removed undefined parameters (doctype, docname, frm)
  // that were causing 400 errors. Use standalone file upload pattern instead.
  new frappe.ui.FileUploader({
    dialog_title: __(dialogTitle),
    files,
    folder: "Home/Attachments",
    disable_file_browser: !files,
    allow_toggle_private: false,
    allow_multiple: true,
    make_attachments_public: true,
    restrictions: {
      allowed_file_types: fileTypes,
    },
    on_success: (file_doc) => {
      const fileType = file_doc.file_url.split(".").pop().toLowerCase();
      let content;
      let file_url = encodeURI(file_doc.file_url);
      if (["mp4", "mov"].includes(fileType)) {
        content = `\n<video controls width="100%" height="auto"><source src="${file_url}" type="video/${fileType}"></video>`;
      } else {
        const fileName =
          file_doc.file_name || file_doc.file_url.split("/").pop();
        const altText = fileName
          .split(".")
          .slice(0, -1)
          .join(".") // without extension
          .replaceAll("_", " ")
          .replaceAll("-", " ");
        content = `\n![${altText}](${file_url})`;
      }
      editor.session.insert(editor.getCursorPosition(), content);
    },
  });
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@GovardhaneNitin GovardhaneNitin closed this by deleting the head repository Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant