tentwentyfour / nextcloud-link

Javascript/Typescript client that communicates with Nextcloud's WebDAV and OCS APIs
MIT License
57 stars 7 forks source link

`uploadFromStream` crashes with `createReadStream` #42

Open maximelafarie opened 3 years ago

maximelafarie commented 3 years ago

In my node project I'm doing the following:

const rs = fs.createReadStream(path.join(config.uploadPathTemp, folderName));

// Create folder recursively
await connector.createRecursiveFolder(path.join(user.target));

// Add files to this folder
await connector.uploadFromStream(path.join(user.target), rs);

The stream is good, the folder exists locally and it waits for being uploaded to NC through nextcloud-link uploadFromStream function. But it throws the following error:

Error:
    at i (/Users/maxime/workspace/my-project/node_modules/nextcloud-link/compiled/client.js:83:35691)
    at ReadStream.t (/Users/maxime/workspace/my-project/node_modules/nextcloud-link/compiled/client.js:83:39772)
    at ReadStream.emit (node:events:394:28)
    at ReadStream.emit (node:domain:470:12)
    at emitErrorNT (node:internal/streams/destroy:193:8)
    at emitErrorCloseNT (node:internal/streams/destroy:158:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  message: [Error: EISDIR: illegal operation on a directory, read] {
    errno: -21,
    code: 'EISDIR',
    syscall: 'read'
  }
}

Am I doing something wrong (do I need to pass some flags to createReadStream?) or is there any stuff related to NC or the lib?

TibixDev commented 2 years ago

You might be trying to read from a directory instead of a file, and you might lack read permissions too. Make sure you are reading a file not a directory.