This client was branched from webdav-fs as the core functionality deserved its own repository. As webdav-fs' API was designed to resemble NodeJS' fs API, little could be done to improve the adapter interface for regular use.
This WebDAV client library is designed to provide an improved API for low-level WebDAV integration. This client uses
window.fetch when available in the browser.
WebDAV client is compatible with NodeJS version 4 (latest minor) and newer. It is also compatible with Webpack when bundling, but not all features can be guaranteed to work (filesystem, streams etc.). Polyfilling for different browsers is almost always the consumer's responsibility.
Please read our contribution guide if you plan on making an issue or PR.
To install for use with NodeJS, execute the following shell command:
npm install webdav --save
Usage is very simple (API) - the main exported object is a factory to create adapter instances:
var createClient = ;var client =;client;
Each method returns a
Basic authentication by default, if
password are provided (if none are provided, no
Authorization header is specified). It also supports OAuth tokens - simply pass the token data to the
These methods can be called on the object returned from the main factory.
copyFile(remotePath, targetPath [, options])
Copy a file or directory from one path to another.
createDirectory(remotePath [, options])
Create a new directory at the remote path.
createReadStream(remotePath [, options])
Creates a readable stream on the remote path.
Returns a readable stream instance.
Optionally request part of the remote file by specifying the
end byte positions. The
end byte position is optional and the rest of the file from
start onwards will be streamed.
var stream = client;
createWriteStream(remotePath [, options])
Creates a writeable stream to a remote path.
Returns a writeable stream instance. Note that the actual stream returned is a Node
PassThroughStream instance, not a
deleteFile(remotePath [, options])
Delete a file or directory at
getDirectoryContents(remotePath [, options])
Get an array of items within a directory.
remotePath is a string that begins with a forward-slash and indicates the remote directory to get the contents of.
The returned value is a Promise, which resolves with an array of item stat objects.
getFileContents(remotePath [, options])
Get the contents of the file at
remotePath as a
format can either be "binary" or "text", where "binary" is default.
var fs = ;client;
Or with text:
Important: When running on Node,
node-fetch is used as the default fetch library.
node-fetch provides the
.buffer() method for responses, which returns a
Buffer instance, but other libraries (and standard
fetch) do not. When the
buffer method is not available, this library will attempt to use
.arrayBuffer. It is your responsibility to handle the output and any required conversion. The
arraybuffer-to-buffer library makes it easy to convert back to a
Buffer if you require it.
getFileDownloadLink(remotePath [, options])
Get the external download link of a remote file. Only supported for non-authenticated connections or connections using Basic authentication.
Important note: This method exposes the username and password in the URL - It is not recommended to send or store any output from this function.
Get quota information. Returns
null upon failure or an object like so:
Both values are provided in bytes in string form.
available may also be one of the following:
unknown: The available space is unknown or not yet calculated
unlimited: The space available is not limited by quotas
moveFile(remotePath, targetPath [, options])
Move a file or directory from
// Move a directoryclient;// Rename a fileclient;
putFileContents(remotePath, data [, options])
Put some data in a remote file at
remotePath from a
data is a
Buffer or a
options has a property called
format which can be "binary" (default) or "text".
var fs = ;var imageData = fs;client;
options, which is optional, can be set to an object like the following:
true), if set to false, will add an additional header which tells the server to abort writing if the target already exists.
stat(remotePath [, options])
Get the stat properties of a remote file or directory at
remotePath. Resolved object is a item stat object.
Overriding the built-in fetch function
Under the hood,
node-fetch to perform requests. This can be overridden by running the following:
// For example, use the `fetch` method in the browser:const createWebDAVClient = ;createWebDAVClient;
Returned data structures
Item stats are objects with properties that descibe a file or directory. They resemble the following:
|filename||String||Always||File path of the remote item|
|basename||String||Always||Base filename of the remote item, no path|
|lastmod||String||Always||Last modification date of the item|
|size||Number||Always||File size - 0 for directories|
|type||String||Always||Item type - "file" or "directory"|
|mime||String||Files only||Mime type - for file items only|
This library has been tested to work with the following WebDAV servers or applications:
Webpack / Browserify
WebDAV-client is browser friendly, after being transpiled. Refer to the use of WebDAV-fs in the Buttercup mobile compatibility library or the Buttercup browser extension for guidance on preparation for the web.
You can also check out the web tests to see a Webpack 4 configuration that bundles this library.
Only Webpack 4 is officially supported in terms of bundlers. Browserify and Rollup should work but are not guaranteed to.