1
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 179 days ago Viewed 383 times
0
Submitted by nextcloud Bun
Verified 10 days ago
1
import * as wmill from "windmill-client";
2
import axios from "axios";
3

4
type Nextcloud = {
5
  baseUrl: string,
6
  password: string,
7
  username: string
8
};
9

10
export async function main(
11
  ncResource: Nextcloud,
12
  userId: string | null = null,
13
  path: string,
14
  useAppApiAuth: boolean = false,
15
) {
16

17
  const res = await axios.get(
18
    `${ncResource.baseUrl}/remote.php/dav/files/${userId || ncResource.username}/${path}`,
19
    {
20
      auth: {
21
        username: userId || ncResource.username,
22
        password: ncResource.password,
23
      },
24
      ...(useAppApiAuth && ({
25
        headers: {
26
          "AA-VERSION": "2.3.0",
27
          "EX-APP-ID": "flow",
28
          "EX-APP-VERSION": "1.0.0",
29
          "AUTHORIZATION-APP-API": btoa(
30
            `${userId || ncResource.username}:${ncResource.password}`,
31
          ),
32
        },
33
      })),
34
    },
35
  );
36
  if (res.status !== 200) {
37
    throw new Error(res.statusText)
38
  }
39
  return res.data
40
}
Other submissions