Copy a file or a folder to a given path in Nextcloud.
1
import axios from "axios";
2
3
export async function main(
4
nextcloud: RT.Nextcloud,
5
sourcePath: string,
6
destinationPath: string,
7
) {
8
9
try {
10
const res = await axios.request(
11
{
12
method: "COPY",
13
url: `/remote.php/dav/files/${nextcloud.userId}/${sourcePath}`,
14
baseURL: nextcloud.baseUrl,
15
headers: {
16
Authorization: `Basic ${btoa(`${nextcloud.userId}:${nextcloud.token}`)
17
}`,
18
Destination: `${nextcloud.baseUrl}/remote.php/dav/files/${nextcloud.userId}/${destinationPath}`,
19
},
20
21
);
22
23
return res.data;
24
} catch (e) {
25
console.log(e.response.data);
26
}
27