Skip to content

[Feature]: Configurable attachments folder for pasted/dropped assets (Obsidian-style) #335

Description

@psoulos

What problem are you trying to solve?

When I paste or drop an image (or other asset) into a document, the file is always stored co-located next to the markdown file in the same folder. There's no way to redirect uploads to a dedicated attachments folder.

Coming from Obsidian, I'm used to specifying an "attachments folder" (e.g. a vault-level attachments/ directory) so that pasted images don't clutter the same folders as my notes, and so embeds resolve to a predictable location. I'd like the same option in OpenKnowledge.

Proposed solution

Expose the already-implemented attachment-folder resolver as a user-facing config setting.

The destination logic already exists and is fully tested in resolveUploadDestDir (packages/server/src/api-extension.ts), with a test suite (packages/server/src/resolve-upload-dest-dir.test.ts) that even names the "P2 Obsidian-refugee case". It already supports all the modes you'd expect:

attachmentFolderPath Result
./ or `` (default) Co-located with the doc (current behavior)
/ Content-directory (vault) root
./attachments Subfolder beside the doc
attachments (bare) Fixed content-relative folder (Obsidian-style)

The only thing missing is the wiring:

  • The upload-asset handler hardcodes the constant instead of reading config:
    // packages/server/src/api-extension.ts (~L8140)
    const destDir = resolveUploadDestDir(
      parentDocName,
      DEFAULT_ATTACHMENT_FOLDER_PATH, // <- hardcoded; should come from config
      resolvedContentDir,
    );
  • The config schema (packages/core/src/config/schema.ts) only exposes content.dir; there's no content.attachmentFolderPath (or similar) field.

Proposed change: add a content.attachmentFolderPath config field (default ./ to preserve current behavior, project scope so it's shared with collaborators) and thread it through to the resolveUploadDestDir call site. The clipboard/drop paste paths in packages/app/src/editor/clipboard and packages/app/src/editor/image-upload would pick up the configured destination automatically since they go through the same upload endpoint.

Area

Editor

Alternatives considered

  • Manually moving pasted files into an attachments folder and fixing up the embed paths by hand — tedious and error-prone.
  • Setting content.dir differently — doesn't help, since that controls the whole document root, not where assets land.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

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