How to customize file path for uploads in webdav utils

I am trying to modify the default filters to customize file path for uploads in the WebDav Utils plug in.

Here is what I am trying to do:

Whenever I am editing a tiddler, this tiddler will become the currentTiddler. I have a field in this tiddler whose fieldvalue will be the name of the subfolder in which the image when drag-dropped should be saved.

As discussed in this post, using this filter

{{{ [{$:/HistoryList!!current-tiddler}fields[]prefix[sub-]] :map[{$:/HistoryList!!current-tiddler}get{!!title}addsuffix[/]] }}}

I will get this folder name for saving the image.

Now I want this be integrated into the filter for file path for uploads. So I made a function for this filter called upload-path in a tiddler tagged with $:/tags/Macro .

\function upload-path()
[{$:/HistoryList!!current-tiddler}fields[]prefix[sub-]] :map[{$:/HistoryList!!current-tiddler}get{!!title}addsuffix[/]]
\end upload-path

Then I modified the filters to customize file path in the WebDav Utils plug in as

\\ last filter matches all remaining tiddlers. replace forward and back slashes and place it inside the default upload directory
[search-replace:g:regexp[/|\\],[_]addprefix<upload-path>addprefix{$:/config/file-uploads/webdav/defaultUploadDirectory}]

But this is not saving the image in the subfolder as intented, but in the files folder . Can somoene help ?

Well, you’re doing better than I am – I can’t get it to save images at all.

It’s unclear what event will trigger the upload. The backup part works though.

And then, 2 seconds later I realise my mistake.

I think the current-tiddler gets changed during the import process. You can paste your filter into the advanced search filter box and see what name it thinks it should use.

You might have to come up with some other strategy. Like an editor button that will take the contents of sub- field and store them away in a tiddler like “current-file-path” which then gets used by your upload filter.

1 Like

Thanks @Mark_S for the suggestion.
I made a custom edit viewtoolbar button which will store the subfolder title in a config tiddler. This config tiddler is used to define the filter in the webdav file upload path

Thanks for that idea. I cloned the edit button because that will be the step prior to drag and drop of images