Nextcloud WebDAV: Upload or update a file
One script reply has been approved by the moderators Verified

Set contents of a file in Nextcloud

Created by marcel klehr12 595 days ago Picked 19 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
  data: string,
7
) {
8

9
  try {
10
    const res = await axios.request(
11
      {
12
        method: "PUT",
13
        url: `/remote.php/dav/files/${nextcloud.userId}/${path}`,
14
        baseURL: nextcloud.baseUrl,
15
        data,
16
        headers: {
17
          Authorization: `Basic ${btoa(`${nextcloud.userId}:${nextcloud.token}`)
18
            }`,
19
        },
20
      },
21
    );
22
    return res.data;
23
  } catch (e) {
24
    console.log(e);
25
    console.log(e.response.data);
26
  }
27
}
Other submissions