Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to export data from multiget #39

Merged
merged 1 commit into from
Nov 5, 2018

Conversation

georgehrke
Copy link
Member

@skjnldsv You can't trigger downloads from an XMLHttpRequest, so you still need to do some browser magic.

Requires nextcloud/server#12004

const client = await new cdav.default({rootUrl: 'http://all.local/nextcloud/remote.php/dav'}, xhrProvider).connect({enableCardDAV: true, enableCalDAV: true});
const addressbooks = await client.addressBookHomes[0].findAllAddressBooks();
const contacts = await addressbooks[0].findAll();
const urls = contacts.slice(2, 8).map((c) => c.url);
const data = await addressbooks[0].addressbookMultigetExport(urls);
const blob = new Blob([data.body], {type: "text/vcard"});
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
const dispositionHeader = data.xhr.getResponseHeader('Content-Disposition');
const filename = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(dispositionHeader)[1].replace(/['"]/g, '');
link.href = url;
link.download = filename;
link.click()

@georgehrke georgehrke force-pushed the feature/noid/addressbook-multiget-and-download branch from 12da1e1 to 415950a Compare November 4, 2018 18:43
@skjnldsv skjnldsv merged commit b211b53 into master Nov 5, 2018
@skjnldsv skjnldsv deleted the feature/noid/addressbook-multiget-and-download branch November 5, 2018 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants