### WebDAV Client Installation via npm Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Shows the command to install the webdav-client library as a project dependency using npm. This is the standard method for adding the library to your project's `node_modules` and `package.json`. ```bash npm install webdav --save ``` -------------------------------- ### GET /stat/:path Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Gets detailed information (stat) about a file or directory, including filename, size, type, modification date, and ETag. ```APIDOC ## GET /stat/:path ### Description Gets detailed information (stat) about a file or directory, including filename, size, type, modification date, and ETag. ### Method GET ### Endpoint `/stat/:path` ### Parameters #### Path Parameters - **path** (string) - Required - The remote path to the file or directory. #### Query Parameters - **details** (boolean) - Optional - If `true`, fetches all available DAV properties returned by the server. #### Request Body None ### Request Example ```typescript // Get file stats const fileStat = await client.stat("/documents/report.pdf"); console.log(fileStat); // Get detailed stats with all properties const detailed = await client.stat("/file.txt", { details: true }); console.log(detailed.data.props); ``` ### Response #### Success Response (200) - **object** - An object containing file/directory statistics. - **filename** (string) - The full remote path. - **basename** (string) - The filename or directory name. - **lastmod** (string) - The last modification date. - **size** (number) - The size of the file in bytes. - **type** (string) - "file" or "directory". - **etag** (string) - The ETag of the file. - **mime** (string) - The MIME type of the file. - **data.props** (object) - (Only if `details: true`) All DAV properties returned by the server. #### Response Example ```json { "filename": "/documents/report.pdf", "basename": "report.pdf", "lastmod": "Tue, 05 Apr 2023 14:39:18 GMT", "size": 1048576, "type": "file", "etag": "abc123def456", "mime": "application/pdf" } ``` ``` -------------------------------- ### Create WebDAV Client (TypeScript) Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Demonstrates how to import and create a WebDAV client instance using TypeScript. This example shows the recommended import methods for both Node.js and browser environments when using version 5 of the library, which relies on ESM. ```typescript import { createClient } from "webdav/web"; // or import { createClient } from "webdav"; // both work fine in supported bundlers ``` -------------------------------- ### GET /api/quota Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Retrieves the quota information for the current account, including used and available storage. ```APIDOC ## GET /api/quota ### Description Get the quota information for the current account. ### Method GET ### Endpoint `/api/quota` ### Parameters #### Query Parameters - **details** (boolean) - Optional - Return detailed results (headers etc.). Defaults to `false`. - **path** (string) - Optional - Path used to make the quota request. ### Request Example ```json { "path": "/" } ``` ### Response #### Success Response (200) - **quota** (DiskQuota | null) - An object containing quota information, or null if unavailable. - **used** (number) - The amount of storage used. - **available** (string | number) - The amount of storage available ("unlimited" or a number). #### Response Example ```json { "used": 1938743, "available": "unlimited" } ``` ``` -------------------------------- ### Create Directory Example - TypeScript Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Illustrates how to create a new directory at a specified path using the WebDAV client. The `createDirectory` method is used, accepting the path as a required argument and an optional `CreateDirectoryOptions` object. The `recursive` option allows for the creation of parent directories if they do not exist. ```typescript await client.createDirectory("/data/system/storage"); ``` -------------------------------- ### TypeScript Type Imports and Client Creation with Authentication Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Illustrates how to import TypeScript types and create a WebDAV client instance with explicit authentication details. This example shows importing `AuthType` and `createClient`, then configuring the client for Digest authentication with a username and password. ```typescript import { AuthType, createClient } from "webdav"; const client = createClient("https://some-server.org", { authType: AuthType.Digest, username: "user", password: "pass" }); ``` -------------------------------- ### Copy File Example - TypeScript Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Demonstrates how to copy a file from a source path to a destination path using the WebDAV client. It utilizes the `copyFile` method, which takes the source and destination filenames as arguments. Optional method options can also be provided. ```typescript await client.copyFile( "/images/test.jpg", "/public/img/test.jpg" ); ``` -------------------------------- ### GET /exists/:path Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Checks whether a file or directory exists at the specified remote path. Returns `true` if it exists, `false` otherwise. ```APIDOC ## GET /exists/:path ### Description Checks whether a file or directory exists at the specified remote path. Returns `true` if it exists, `false` otherwise. ### Method GET ### Endpoint `/exists/:path` ### Parameters #### Path Parameters - **path** (string) - Required - The remote path to check. #### Query Parameters None #### Request Body None ### Request Example ```typescript // Check if path exists if (await client.exists("/backup")) { console.log("Backup directory exists"); } else { await client.createDirectory("/backup"); } ``` ### Response #### Success Response (200) - **boolean** - `true` if the path exists, `false` otherwise. #### Response Example ```json true ``` ``` -------------------------------- ### Get Disk Quota Information (TypeScript) Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Retrieves the disk quota information for the current account, including used space and available space. Options can specify whether to fetch detailed results or a specific path for the quota request. ```typescript const quota: DiskQuota = await client.getQuota(); // Example output: // { // "used": 1938743, // "available": "unlimited" // } ``` -------------------------------- ### GET /api/fileContents Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Fetches the contents of a remote file. Can return binary data (Buffer) or text content. ```APIDOC ## GET /api/fileContents ### Description Fetch the contents of a remote file. Binary contents are returned by default (`Buffer`). ### Method GET ### Endpoint `/api/fileContents` ### Parameters #### Query Parameters - **filename** (string) - Required - The file to fetch the contents of. - **details** (boolean) - Optional - Fetch detailed results (additional headers). Defaults to `false`. - **format** (string) - Optional - Whether to fetch binary ("binary") data or textual ("text"). Defaults to "binary". ### Request Example ```json { "filename": "/config.json", "format": "text" } ``` ### Response #### Success Response (200) - **content** (Buffer | string) - The content of the file, either as a Buffer for binary data or a string for text data. #### Response Example ```json "{\"key\": \"value\"}" ``` ``` -------------------------------- ### Get Disk Quota Information with WebDAV Client Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Retrieves disk quota information, including used and available space, for the current account or a specific path. Supports options for detailed responses. Requires a configured WebDAV client instance. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Get quota information const quota = await client.getQuota(); console.log(quota); // { used: 1938743, available: 10737418240 } // or { used: 1938743, available: "unlimited" } // or { used: 1938743, available: "unknown" } // Get quota for specific path const pathQuota = await client.getQuota({ path: "/shared" }); // Get detailed quota response const detailed = await client.getQuota({ details: true }); console.log(detailed.data.used); // Bytes used console.log(detailed.data.available); // Bytes available or "unlimited"/"unknown" ``` -------------------------------- ### GET /stat Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Retrieves the stat object for a given file or directory. This provides metadata about the item. ```APIDOC ## GET /stat ### Description Retrieves the stat object for a given file or directory. This provides metadata about the item. ### Method GET ### Endpoint /stat ### Parameters #### Path Parameters - **path** (string) - Required - The remote path to the file or directory to stat. #### Query Parameters - **details** (boolean) - Optional - Return detailed results (headers etc.). Defaults to `false`. #### Request Body None ### Request Example ```typescript const stat: FileStat = await client.stat("/some/file.tar.gz"); ``` ### Response #### Success Response (200) - **FileStat** - An item stat object containing metadata about the file or directory. #### Response Example ```json { "example": "FileStat object" } ``` ``` -------------------------------- ### Get Item Stat Object Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Retrieves the stat object for a given file or directory. The stat object contains metadata about the item. Detailed results, including headers, can be optionally returned. ```typescript const stat: FileStat = await client.stat("/some/file.tar.gz"); ``` ```typescript (path: string, options?: StatOptions) => Promise> ``` -------------------------------- ### GET /api/directoryContents Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Retrieves the contents of a remote directory. Supports deep recursion and glob pattern matching for filtering files. ```APIDOC ## GET /api/directoryContents ### Description Get the contents of a remote directory. Returns an array of item stats. ### Method GET ### Endpoint `/api/directoryContents` ### Parameters #### Query Parameters - **path** (string) - Required - The path to fetch the contents of. - **deep** (boolean) - Optional - Fetch deep results (recursive). Defaults to `false`. - **details** (boolean) - Optional - Fetch detailed results (item stats, headers). Defaults to `false`. - **glob** (string) - Optional - Glob string for matching filenames. Not set by default. ### Request Example ```json { "path": "/", "deep": true, "glob": "/**/*.{png,jpg,gif}" } ``` ### Response #### Success Response (200) - **contents** (Array) - An array of file statistics for the items in the directory. #### Response Example ```json [ { "type": "file", "name": "example.txt", "size": 1024, "lastModified": "2023-10-27T10:00:00Z" } ] ``` ``` -------------------------------- ### Get DAV Compliance and Server Info - TypeScript Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Retrieves WebDAV compliance classes and server information for a resource using `getDAVCompliance`. This is useful for detecting server capabilities and features like partial update support. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Check server capabilities const compliance = await client.getDAVCompliance("/"); console.log(compliance); // { // compliance: ["1", "2", "3", "sabredav-partialupdate"], // server: "Apache/2.4.41 (Ubuntu)" // } // Check for specific features if (compliance.compliance.includes("sabredav-partialupdate")) { console.log("Server supports partial file updates"); } ``` -------------------------------- ### Get File or Directory Information (Stat) via WebDAV Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Retrieves detailed information about a file or directory on a WebDAV server. This includes metadata such as filename, size, modification date, type (file/directory), and ETag. An option exists to fetch all available DAV properties. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Get file stats const fileStat = await client.stat("/documents/report.pdf"); console.log(fileStat); // { // filename: "/documents/report.pdf", // basename: "report.pdf", // lastmod: "Tue, 05 Apr 2023 14:39:18 GMT", // size: 1048576, // type: "file", // etag: "abc123def456", // mime: "application/pdf" // } // Get directory stats const dirStat = await client.stat("/documents"); console.log(dirStat.type); // "directory" // Get detailed stats with all properties const detailed = await client.stat("/file.txt", { details: true }); console.log(detailed.data.props); // All DAV properties returned by server ``` -------------------------------- ### Basic WebDAV Client Usage and Directory Listing Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Demonstrates the fundamental usage of the webdav-client library. It shows how to create a client instance with a URL and credentials, and then how to call `getDirectoryContents` to retrieve information about files and directories within a specified path. The output format for directory items is also illustrated. ```typescript const { createClient } = require("webdav"); const client = createClient( "https://webdav.example.com/marie123", { username: "marie", password: "myS3curePa$$w0rd" } ); // Get directory contents const directoryItems = await client.getDirectoryContents("/"); // Outputs a structure like: // [{ // filename: "/my-file.txt", // basename: "my-file.txt", // lastmod: "Mon, 10 Oct 2018 23:24:11 GMT", // size: 371, // type: "file" // }] ``` -------------------------------- ### GET /api/fileUploadLink Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Generates a URL for uploading a file. This method is synchronous and exposes authentication details in the URL. ```APIDOC ## GET /api/fileUploadLink ### Description Generate a URL for a file upload. This method is synchronous. **Exposes authentication details in the URL**. ### Method GET ### Endpoint `/api/fileUploadLink` ### Parameters #### Query Parameters - **filename** (string) - Required - The remote file to generate an upload link for. ### Request Example ```json { "filename": "/image.png" } ``` ### Response #### Success Response (200) - **uploadLink** (string) - The URL for uploading the file. #### Response Example ```json "https://example.com/dav/image.png?auth=token" ``` ``` -------------------------------- ### Client Configuration Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md The `createClient` method initializes a WebDAV client with a service URL and configuration options. ```APIDOC ## Client Configuration The `createClient` method takes a WebDAV service URL and a configuration options parameter. ### Options | Option | Default | Description | |---|---|---| | `authType` | `null` | The authentication type to use. Defaults to detecting based on `username` and `password` if provided. | | `attributeNamePrefix` | `@` | Prefix used to identify attributes on the property object. | | `contactHref` | _[This URL](https://github.com/perry-mitchell/webdav-client/blob/master/LOCK_CONTACT.md)_ | Contact URL used for LOCK requests. | | `headers` | `{}` | Additional headers to include in all requests. These can be overridden by method-specific headers. | | `httpAgent` | _None_ | HTTP agent instance (Node.js specific). | | `httpsAgent` | _None_ | HTTPS agent instance (Node.js specific). | | `password` | _None_ | Password for basic authentication. | | `token` | _None_ | Token object for token-based authentication. | | `username` | _None_ | Username for basic authentication. | | `withCredentials` | _None_ | Credentials inclusion setting for the request. ``` -------------------------------- ### POST /directories Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Creates a new directory at the specified path. Supports recursive creation to build entire directory trees in a single call. ```APIDOC ## POST /directories ### Description Creates a new directory at the specified path. Supports recursive creation to build entire directory trees in a single call. ### Method POST ### Endpoint `/directories` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **path** (string) - Required - The remote path for the new directory. - **options** (object) - Optional - Configuration options. - **recursive** (boolean) - Optional - If `true`, creates parent directories as needed. Defaults to `false`. ### Request Example ```typescript // Create single directory await client.createDirectory("/new-folder"); // Create nested directories recursively await client.createDirectory("/projects/2024/january/reports", { recursive: true }); ``` ### Response #### Success Response (201) - **void** - Indicates successful creation. #### Response Example (No response body on success) ``` -------------------------------- ### GET /api/fileDownloadLink Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Generates a public download link for a remote file. This method is synchronous and exposes authentication details in the URL. ```APIDOC ## GET /api/fileDownloadLink ### Description Generate a public link where a file can be downloaded. This method is synchronous. **Exposes authentication details in the URL**. _Not all servers may support this feature. Only Basic authentication and unauthenticated connections support this method._ ### Method GET ### Endpoint `/api/fileDownloadLink` ### Parameters #### Query Parameters - **filename** (string) - Required - The remote file to generate a download link for. ### Request Example ```json { "filename": "/image.png" } ``` ### Response #### Success Response (200) - **downloadLink** (string) - The public URL for downloading the file. #### Response Example ```json "https://example.com/dav/image.png?auth=token" ``` ``` -------------------------------- ### getQuota Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Retrieves disk quota information for the current account, showing used and available space. ```APIDOC ## GET /getQuota ### Description Retrieves disk quota information for the current account, showing used and available space. ### Method GET ### Endpoint /getQuota ### Parameters #### Query Parameters - **path** (string) - Optional - The path to check quota for. Defaults to the root. - **details** (boolean) - Optional - If true, returns detailed quota information. Defaults to false. ### Request Example ```json { "path": "/shared", "details": true } ``` ### Response #### Success Response (200) - **used** (number) - The amount of disk space used in bytes. - **available** (number | string) - The amount of disk space available in bytes, or "unlimited" or "unknown". - **data** (object) - Only present if `details` is true. Contains detailed quota information. - **used** (number) - Bytes used. - **available** (number | string) - Bytes available or "unlimited"/"unknown". #### Response Example ```json { "used": 1938743, "available": 10737418240 } ``` #### Detailed Response Example ```json { "used": 1938743, "available": "unlimited", "data": { "used": 1938743, "available": "unlimited" } } ``` ``` -------------------------------- ### createDirectory Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Creates a new directory on the WebDAV server. Supports recursive creation. ```APIDOC ## POST /createDirectory ### Description Creates a new directory. ### Method POST ### Endpoint `/createDirectory` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Uses method arguments) ### Request Example ```javascript await client.createDirectory("/data/system/storage"); ``` ### Parameters (Method Arguments) - **path** (string) - Required - The path to create. - **options** (CreateDirectoryOptions) - Optional - Create directory options. - **recursive** (boolean) - Optional - Recursively create directories if they do not exist. _`options` extends [method options](#method-options)._ ##### Recursive creation Recursive directory creation is expensive request-wise. Multiple `stat` requests are made to detect existing path segments before creating new ones. ### Response #### Success Response (200) Returns `void` upon successful creation. #### Response Example None (void return) ``` -------------------------------- ### Method Options Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md WebDAV methods can be configured using options that extend `WebDAVMethodOptions`. These options allow for customization of requests, such as adding custom headers or aborting requests. ```APIDOC ## Method Options Most WebDAV methods extend `WebDAVMethodOptions`, which allow setting things like custom headers. ### Options | Option | Required | Description | |-----------|-----------|-----------------------------------------------| | `data` | No | Optional body/data value to send in the request. This overrides the original body of the request, if applicable. | | `headers` | No | Optional headers object to apply to the request. These headers override all others, so be careful. | | `signal` | No | Instance of [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal), for aborting requests. | ``` -------------------------------- ### Set and Get Custom Request Headers - TypeScript Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Manages custom headers for all subsequent requests using `setHeaders` and `getHeaders`. `getHeaders` retrieves the current headers, while `setHeaders` allows updating them with a new object. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Get current headers const currentHeaders = client.getHeaders(); console.log(currentHeaders); // { Authorization: "Basic ..." } // Set new custom headers client.setHeaders({ "X-Custom-Header": "custom-value", "Accept-Language": "en-US" }); // Headers are now included in all requests await client.getDirectoryContents("/"); ``` -------------------------------- ### Create WebDAV Client Instance (TypeScript) Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Instantiates a WebDAV client with the server URL and authentication details. Supports Basic, Digest, and Token (OAuth) authentication types, along with custom headers and agents. ```typescript import { createClient, AuthType } from "webdav"; // Basic authentication const client = createClient("https://webdav.example.com/remote.php/dav/files/username", { username: "user@example.com", password: "mySecurePassword123" }); // Digest authentication const digestClient = createClient("https://webdav.example.com/dav", { authType: AuthType.Digest, username: "admin", password: "secretPass" }); // OAuth token authentication const oauthClient = createClient("https://webdav.example.com/dav", { authType: AuthType.Token, token: { access_token: "2YotnFZFEjr1zCsicMWpAA", token_type: "Bearer", refresh_token: "tGzv3JOkF0XG5Qx2TlKWIA" } }); // With custom headers and agents const customClient = createClient("https://webdav.example.com/dav", { username: "user", password: "pass", headers: { "X-Custom-Header": "custom-value" } }); ``` -------------------------------- ### Get File Contents (TypeScript) Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Fetches the content of a remote file, returning it as a Buffer (Node.js) or ArrayBuffer (browser) by default, or as a text string if specified. Supports detailed responses including headers and status codes. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Get binary file contents (default) const imageBuffer = await client.getFileContents("/images/photo.jpg"); // Returns Buffer in Node.js, ArrayBuffer in browser // Get text file contents const configText = await client.getFileContents("/config.json", { format: "text" }); console.log(JSON.parse(configText)); // Get file with detailed response const detailed = await client.getFileContents("/document.pdf", { details: true }); console.log(detailed.data); // File contents console.log(detailed.headers); // Response headers console.log(detailed.status); // 200 console.log(detailed.statusText); // "OK" ``` -------------------------------- ### exists Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Check if a file or directory exists. ```APIDOC ## GET /exists ### Description Check if a file or directory exists. ### Method GET ### Endpoint /exists ### Parameters #### Path Parameters - **path** (string) - Yes - The remote path to check. #### Query Parameters - **options** (object) - No - [Method options](#method-options). ### Request Example ```typescript if (await client.exists("/some/path") === false) { await client.createDirectory("/some/path"); } ``` ### Response #### Success Response (200) - **exists** (boolean) - `true` if the file or directory exists, `false` otherwise. #### Response Example ```typescript const fileExists = await client.exists("/some/file.txt"); console.log(fileExists); // true or false ``` ``` -------------------------------- ### Get Directory Contents (TypeScript) Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Retrieves the contents of a remote directory. Supports recursive listing (`deep: true`) and filtering with glob patterns. Can also fetch detailed responses including headers and status codes. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Get root directory contents const contents = await client.getDirectoryContents("/"); console.log(contents); // [ // { filename: "/Documents", basename: "Documents", type: "directory", size: 0, lastmod: "Mon, 10 Oct 2023 10:00:00 GMT", etag: null }, // { filename: "/photo.jpg", basename: "photo.jpg", type: "file", size: 42497, lastmod: "Sun, 13 Mar 2023 04:23:32 GMT", mime: "image/jpeg", etag: "33a728c7f288ede1fecc90ac6a10e062" } // ] // Get all contents recursively const allFiles = await client.getDirectoryContents("/", { deep: true }); // Filter with glob pattern const images = await client.getDirectoryContents("/", { deep: true, glob: "/**/*.{png,jpg,gif}" }); // Get detailed response with headers const detailed = await client.getDirectoryContents("/Documents", { details: true }); console.log(detailed.data); // Array of FileStat objects console.log(detailed.headers); // Response headers console.log(detailed.status); // HTTP status code ``` -------------------------------- ### Get Directory Contents with Globbing (TypeScript) Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Retrieves the contents of a remote directory. Supports recursive fetching ('deep' option) and filename matching using glob patterns ('glob' option), which is processed by 'minimatch'. It returns an array of file statistics. ```typescript const contents = await client.getDirectoryContents("/"); const contents = await client.getDirectoryContents("/", { deep: true }); const images = await client.getDirectoryContents("/", { deep: true, glob: "/**/*.{png,jpg,gif}" }); ``` -------------------------------- ### copyFile Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Copies a file or directory from one location to another on the remote server. Supports shallow copies for directories and overwrite control. ```APIDOC ## POST /copyFile ### Description Copies a file or directory from one location to another on the remote server. Supports shallow copies for directories and overwrite control. ### Method POST ### Endpoint /copyFile ### Parameters #### Query Parameters - **source** (string) - Required - The source path of the file or directory to copy. - **destination** (string) - Required - The destination path for the copied file or directory. - **overwrite** (boolean) - Optional - If true, overwrite the destination if it already exists. Defaults to true. - **shallow** (boolean) - Optional - If true, performs a shallow copy of a directory (copies the directory itself, not its contents). Defaults to false. ### Request Example ```json { "source": "/documents/original.pdf", "destination": "/backup/original.pdf", "overwrite": true, "shallow": false } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the copy operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### React Native Specific Import for WebDAV Client Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Demonstrates how to import the WebDAV client specifically for React Native environments. This ensures the correct build is used, which can be crucial for platform-specific optimizations. It's recommended to use this import path when working within a React Native project. ```typescript import { createClient } from "webdav/react-native"; ``` -------------------------------- ### Execute Custom HTTP Requests Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Executes a custom HTTP request against the WebDAV server with automatic authentication handling. Useful for server-specific extensions or unsupported methods. Supports methods like PROPFIND and PROPPATCH, allowing for custom headers and data payloads. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Custom PROPFIND request const response = await client.customRequest("/file.jpg", { method: "PROPFIND", headers: { Accept: "text/plain", Depth: "0" } }); const xmlResponse = await response.text(); console.log(xmlResponse); // Custom PROPPATCH request const proppatchXML = ` New Display Name `; await client.customRequest("/my-file.txt", { method: "PROPPATCH", headers: { "Content-Type": "application/xml" }, data: proppatchXML }); ``` -------------------------------- ### Update File Contents Partially - TypeScript Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Updates a portion of a remote file using `partialUpdateFileContents`. This method requires server support for partial updates. It accepts a file path, start and end byte indices, and the new data (Buffer or string). ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Update bytes 100-199 of a file const newData = Buffer.from("updated content here"); await client.partialUpdateFileContents( "/large-file.bin", 100, // start byte (inclusive) 119, // end byte (inclusive) newData ); // Partial update with string data await client.partialUpdateFileContents( "/text-file.txt", 0, 11, "Hello World!" ); ``` -------------------------------- ### Generate Public File Download/Upload Links Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Generates public URLs for file download or upload that include authentication credentials. Only works with Basic authentication or unauthenticated connections. These URLs expose credentials and should be used with caution. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Generate download link (includes credentials in URL) const downloadLink = client.getFileDownloadLink("/public/document.pdf"); console.log(downloadLink); // https://user:pass@webdav.example.com/dav/public/document.pdf // Generate upload link const uploadLink = client.getFileUploadLink("/uploads/new-file.txt"); console.log(uploadLink); // https://user:pass@webdav.example.com/dav/uploads/new-file.txt?Content-Type=application/octet-stream // Use in external contexts (e.g., pass to download manager) // WARNING: These URLs expose credentials - use with caution ``` -------------------------------- ### Babel Configuration for React Native WebDAV Import Resolution Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Provides a Babel configuration snippet to resolve the 'webdav' import path correctly within React Native projects. This is necessary because the Metro build system might not automatically resolve the correct entry point for the library. The configuration maps 'webdav' to the specific React Native build directory. ```javascript module.exports = { presets: ["module:metro-react-native-babel-preset"], plugins: [ [ "module-resolver", { alias: { // Point the webdav client entry to the react native build: webdav: "webdav/dist/react-native" }, extensions: [".tsx", ".ts", ".js", ".jsx", ".json"] } ] ] }; ``` -------------------------------- ### copyFile Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Copies a file from a source location to a destination location on the WebDAV server. ```APIDOC ## POST /copyFile ### Description Copies a file from one location to another. ### Method POST ### Endpoint `/copyFile` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (Uses method arguments) ### Request Example ```javascript await client.copyFile( "/images/test.jpg", "/public/img/test.jpg" ); ``` ### Response #### Success Response (200) Returns `void` upon successful copy. #### Response Example None (void return) ``` -------------------------------- ### Detailed Response Structure with Attributes (JSON) Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Illustrates a detailed response structure for WebDAV requests when `details: true` is enabled. It includes the original data, response headers, status code, status text, and a 'props' object containing server-specific attributes, which can be accessed using a prefix. ```json { "headers": {}, "status": 200, "statusText": "Ok", "data": { "filename": "/1", "basename": "1", "lastmod": "Wed, 24 Jul 2024 19:46:09 GMT", "size": 0, "type": "file", "etag": "66a15a0171527", "mime": "", "props": { "getetag": "\"66a15a0171527\"", "getlastmodified": "Wed, 24 Jul 2024 19:46:09 GMT", "creationdate": "1970-01-01T00:00:00+00:00", "system-tags": { "system-tag": [ { "text": "Tag1", "@can-assign": "true", "@id": "321", "@checked": true }, { "text": "Tag2", "@can-assign": "false", "@id": "654", "@prop": "" } ] } } } } ``` -------------------------------- ### Client Customization: Attribute and Tag Parsers Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Allows registration of custom parsers for attributes and tags to customize how WebDAV data is interpreted. ```APIDOC ## Client Customization: Attribute and Tag Parsers ### Description Allows registration of custom parsers for attributes and tags to customize how WebDAV data is interpreted. This is useful for handling non-standard XML attributes or element values. ### Method `registerAttributeParser(parser: WebDAVAttributeParser)` `registerTagParser(parser: WebDAVTagParser)` ### Endpoint N/A (Client-side method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript // Parses all `disabled` attributes to boolean, e.g. `` function booleanAttributeParser(jPath: string, value: string) { if (jPath.endsWith(".disabled")) { return value === "true"; } // Apply default parsing otherwise return value; } await client.registerAttributeParser(booleanAttributeParser); // Parses only `JSONVALUE` function jsonPropParser(jPath: string, value: string) { if (jPath.endsWith("prop.json-prop")) { return JSON.parse(value); } // Apply default parsing otherwise return value; } await client.registerTagParser(jsonPropParser); ``` ### Response #### Success Response (200) - (void) - Indicates the parser was successfully registered. #### Response Example ```json { "example": "Success" } ``` ### Note on Custom Properties For requests like `stat` (which use `PROPFIND`), you can provide a custom request body by setting the `data` property in the method options to include additional or different server-respondable data. ``` -------------------------------- ### Copy File/Directory with WebDAV Client Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Copies a file or directory on the remote server. Supports options for shallow copies, deep copies (default), and overwrite control. Requires a configured WebDAV client instance. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Copy a file await client.copyFile("/documents/original.pdf", "/backup/original.pdf"); // Copy with overwrite disabled (fails if destination exists) await client.copyFile("/source.txt", "/dest.txt", { overwrite: false }); // Shallow copy (directory only, not contents) await client.copyFile("/folder", "/folder-copy", { shallow: true }); // Deep copy (directory with all contents - default) await client.copyFile("/project", "/project-backup"); ``` -------------------------------- ### createWriteStream Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Create a write stream targeted at a remote file. The connection and writing are performed asynchronously in the background. ```APIDOC ## POST /createWriteStream ### Description Create a write stream targeted at a remote file. The connection and writing to the remote file is still performed asynchronously in the background. ### Method POST ### Endpoint /createWriteStream ### Parameters #### Path Parameters - **filename** (string) - Yes - The remote file to stream. #### Query Parameters - **options** (object) - No - Write stream options. - **overwrite** (boolean) - No - Whether or not to overwrite the remote file if it already exists. Defaults to `true`. - **callback** (function) - No - Callback to fire once the connection has been made and streaming has started. Callback is called with the response of the request. ### Request Example ```typescript fs.createReadStream("~/Music/song.mp3").pipe(client.createWriteStream("/music/song.mp3", { overwrite: false })); ``` ### Response #### Success Response (200) - **stream** (Stream.Writable) - A writable stream for the remote file. #### Response Example ```typescript fs.createReadStream("~/Music/song.mp3").pipe(client.createWriteStream("/music/song.mp3")); ``` ``` -------------------------------- ### File Download/Upload Link Generation Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Generates public URLs for file download or upload that include authentication credentials. Only works with Basic authentication or unauthenticated connections. ```APIDOC ## GET /getFileDownloadLink ### Description Generates a pre-signed URL for downloading a file. ### Method GET ### Endpoint `/getFileDownloadLink` ### Parameters #### Query Parameters - **path** (string) - Required - The path to the file to download. ### Request Body (Not applicable for this endpoint) ### Response #### Success Response (200) - **url** (string) - The generated download URL, including authentication credentials if applicable. #### Response Example ``` https://user:pass@webdav.example.com/dav/public/document.pdf ``` ## GET /getFileUploadLink ### Description Generates a pre-signed URL for uploading a file. ### Method GET ### Endpoint `/getFileUploadLink` ### Parameters #### Query Parameters - **path** (string) - Required - The path where the file should be uploaded. ### Request Body (Not applicable for this endpoint) ### Response #### Success Response (200) - **url** (string) - The generated upload URL, including authentication credentials and potential content type parameters. #### Response Example ``` https://user:pass@webdav.example.com/dav/uploads/new-file.txt?Content-Type=application/octet-stream ``` ``` -------------------------------- ### WebDAV Client Configuration with OAuth Token Authentication Source: https://github.com/perry-mitchell/webdav-client/blob/master/README.md Explains how to configure the WebDAV client for authentication using an OAuth token. This involves specifying `AuthType.Token` and providing the token details, including `access_token`, `token_type`, and optionally `refresh_token` and other custom parameters. ```typescript createClient( "https://address.com", { authType: AuthType.Token, token: { access_token: "2YotnFZFEjr1zCsicMWpAA", token_type: "example", expires_in: 3600, refresh_token: "tGzv3JOkF0XG5Qx2TlKWIA", example_parameter: "example_value" } } ); ``` -------------------------------- ### PUT /files/:path Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Writes data to a remote file. Supports strings, buffers, and streams. Can prevent overwriting and specify content length. ```APIDOC ## PUT /files/:path ### Description Writes data to a remote file. Supports strings, buffers, and streams. Returns `true` on success, `false` if the file exists and overwrite is disabled. ### Method PUT ### Endpoint `/files/:path` ### Parameters #### Path Parameters - **path** (string) - Required - The remote path to the file. #### Query Parameters None #### Request Body - **data** (string | Buffer | ReadableStream) - Required - The content to write to the file. - **options** (object) - Optional - Configuration options. - **overwrite** (boolean) - Optional - If `false`, prevents overwriting an existing file. Defaults to `true`. - **contentLength** (number | false) - Optional - Explicitly set the `Content-Length` header. If `false`, the server will handle chunked transfer encoding. ### Request Example ```typescript // Write string content await client.putFileContents("/notes/readme.txt", "Hello, WebDAV!"); // Write buffer const imageBuffer = fs.readFileSync("./local-image.jpg"); await client.putFileContents("/images/uploaded.jpg", imageBuffer); // Prevent overwriting existing files const written = await client.putFileContents("/important.txt", "data", { overwrite: false }); // Write from readable stream const readStream = fs.createReadStream("./large-video.mp4"); await client.putFileContents("/videos/movie.mp4", readStream, { contentLength: false // Let server handle chunked transfer }); ``` ### Response #### Success Response (200) - **boolean** - `true` if the file was written successfully, `false` if `overwrite` was `false` and the file already existed. #### Response Example ```json true ``` ``` -------------------------------- ### moveFile Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Moves a file or directory from one location to another on the remote server. This is effectively a rename operation when moving within the same directory. ```APIDOC ## POST /moveFile ### Description Moves a file or directory from one location to another on the remote server. This is effectively a rename operation when moving within the same directory. ### Method POST ### Endpoint /moveFile ### Parameters #### Query Parameters - **source** (string) - Required - The source path of the file or directory to move. - **destination** (string) - Required - The destination path for the moved file or directory. - **overwrite** (boolean) - Optional - If true, overwrite the destination if it already exists. Defaults to true. ### Request Example ```json { "source": "/draft.txt", "destination": "/final.txt", "overwrite": false } ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the move operation was successful. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Create Directory on WebDAV Source: https://context7.com/perry-mitchell/webdav-client/llms.txt Creates a new directory at the specified path on the WebDAV server. The `recursive` option allows for the creation of nested directory structures in a single operation. This function is essential for organizing files and preparing upload destinations. ```typescript import { createClient } from "webdav"; const client = createClient("https://webdav.example.com/dav", { username: "user", password: "pass" }); // Create single directory await client.createDirectory("/new-folder"); // Create nested directories recursively await client.createDirectory("/projects/2024/january/reports", { recursive: true }); // Ensure directory exists before uploading if (!(await client.exists("/uploads/images"))) { await client.createDirectory("/uploads/images", { recursive: true }); } await client.putFileContents("/uploads/images/photo.jpg", imageBuffer); ```