A simple webdav library for browsers and node.js
Webdav.js is a Object-Oriented and Promise based client library for webdav servers. It allows inspecting, downloading and uploading files.
In order for cross origin access to a webdav server to work, you need to set CORS appropriate headers. Otherwise this library won't work.
import * as webdav from './webdav.js';
const url = 'http://localhost:8080/dav';
const client = new webdav.Client(url, {
username: 'username',
password: 'password',
});
(async function run() {
const root = await client.getRoot();
const files = {
'lyrics.txt': 'Oh, think twice',
'youandme.txt': 'Another file in paradise',
}
const demofolder = await root.mkdir('demo');
for (const [file, content] of Object.entries(files)) {
await demofolder.upload(file, content);
}
const filelist = await demofolder.list();
console.log(filelist);
const downloads = await Promise.all(filelist.map(async file=>await file.download()));
for (const file of downloads) {
console.log('Downloaded', file);
}
})();
Creates a new client instance.
List all entities in the given dir.
Downloads a file given a href.
Downloads a file given a href. Reports Progress.
Uploads some data to a file at the given a href.
Uploads some data to a file at the given a href. Reports Progress.
Moves the entity at href to a new location loc.
Moves the entity at href.
Creates a directory at a given href.
Inspects a given href.
Inspects the servers root directory. This is a convenient entrypoint for the Object-Oriented model.
Add a parsing function for a given mime-type. The parsing function should accept a Response instance and return the decoded data.
The entities href
The entities displayname
The entities resourcetype
The entities creation date
The entities last modification date
The entities etag
Gets the entities parent directory
Moves the entity to a new location
Renames the entity
Deletes the entity
Reloads the entity by returning a new, updated one
The directories name
Lists all files in this directory
Uploads a new file to this directory
Uploads a new file to this directory. Reports Progress.
Created a new directory inside this one
The files name
The files length (in Bytes)
The files mime-type
Downloads the file contents and decodes it using a TypeParser (see Client:addTypeParser).
Downloads the file contents. Reports Progress.
Updates the files contents.
Updates the files contents. Reports Progress
The transactions upload progress in percent
The transactions download progress in percent
Flag if the transaction is done
If an error occured, this field will be set to that error
The underlying XMLHttpRequest instance