Nextcloud WebDAV: Get the content of a file
One script reply has been approved by the moderators Verified

Get file contents of a file in Nextcloud

Created by marcel klehr12 595 days ago Picked 30 times
Submitted by nextcloud Bun
Verified 21 days ago
1
import axios from "axios";
2

3
export async function main(
4
  nextcloud: RT.Nextcloud,
5
  path: string,
6
) {
7

8
  const res = await axios.get(
9
    `${nextcloud.baseUrl}/remote.php/dav/files/${nextcloud.userId}/${path}`,
10
    {
11
      auth: {
12
        username: nextcloud.userId,
13
        password: nextcloud.token,
14
      },
15
    },
16
  );
17
  if (res.status !== 200) {
18
    throw new Error(res.statusText)
19
  }
20
  return res.data
21
}
Other submissions