Nextcloud Integration: List -> Download File fails with whitespaces

Hi,

new n8n user here!
I am currently trying to implement a workflow which should download content from a given nextcloud directory and move it to a mount where paperless picks it up.

Everything works fine so far except if a file has whitespaces in it e.g. instead of “someName.pdf” “some name.pdf”

The error I receive looks like this:

ERROR: The resource you are requesting could not be found
404 - "\n\n Sabre\\DAV\\Exception\\NotFound\n File with name Rechnungen/Some%Name%20with%20spaces.pdf could not be located\n\n" - Sabre\DAV\Exception\NotFound File with name Rechnungen/Some%Name%20with%20spaces.pdf could not be located

I´ve already tried to sanatize the filename and had a approach with different encoding aswell as remove whitespaces but no luck for now.

Hopefully someone here can point me out what I am missing.

Additional Details / Summary:

  • Error on Node 3 (Nextcloud download:file) error description above
  • N8N aswell as nextcloud are running dockerized
  • Files without white spaces are working as expected

Workflow summary:

  • List all files from a specific nextcloud dir
  • use list to download each file
  • function node with JS to append custom string before extension
  • write binary file(s) to paperless consume directory
  • delete files from nextcloud (to not mess with file indexer)

Hardware specific:

  • OS Host mint
  • Running n8n in a docker container
  • n8n version: 1.18.2
  • db: mysql (mariadb)

If you need any additional details, please let me know.
Thanks in advance!

/edit: workflow fix + db info

Workflow:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hey @Midoxx,

Is it just the download that fails when there is a space in the name or do other actions fail as well? Normally I would expect the name to be encoded with %20 replacing the space like you have in your error but maybe Nextcloud doesn’t like that.

I will see if I can find a NextCloud instance somewhere and do a test.

I can confirm that this happens to my setup too.

Downloading a file, which link is taken from the listing node, fails.

I could test other cases if you ask me what.

Hi @Jon

Thank you for your response! I had overlooked this issue earlier but have since resolved it.

For your information and for future readers:
It appears that Nextcloud does not support encoded strings when accessing files later on. On the other hand, n8n correctly employs encoding, replacing spaces in filenames with placeholders. To work with Nextcloud, it’s necessary to revert these placeholders back to spaces in the original filename.

To address this, I’ve implemented a script following the download process to appropriately transform the string.

Script:

return items.map(item => {
  let fullPath = item.json.filePath; //Adjust path 

  const lastSlashIndex = fullPath.lastIndexOf('/');
  const directoryPath = fullPath.substring(0, lastSlashIndex + 1); // Includes the trailing slash
  let filename = fullPath.substring(lastSlashIndex + 1);

  filename = filename.replace(/ /g, '%20');

  const encodedFullPath = directoryPath + filename;

  item.json.filePath = encodedFullPath;

  return item; // Return the modified item to the next node
});

@arjon hope this helps you!

1 Like

How do you use this code? Can you please paste your workflow?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.