West-Life Virtual Research Environment Docs
  • Introduction
  • Data Management
  • Virtual Folder
    • User's guide
      • Settings
        • Import settings from another Virtual Folder
      • File Manager
      • File Picker
      • Related applications
        • Jupyter notebook
      • Metadata
    • Installation guide
      • Cloud installation
      • Local installation
      • Integration with SSO
    • Integration guide
      • Select File or Dir from Virtual Folder
      • Working with WEBDAV
      • Embedding Virtual Folder Component
      • Adding component into Virtual Folder
    • Developer's guide
      • Backend
      • Frontend - Web Application
      • Metadata and API
        • Dataset metadata and API
        • File metadata and API
      • Import Export Settings API
      • Related application and services
      • Untitled
  • Virtual Machines and Containers
    • Preparing vagrant VM template
    • Preparing docker container
  • Repository
    • Installation guide
      • Prerequisites
      • Automatic installation
      • Manual installation from source codes
    • User's guide
      • Scientist imports project proposal
      • Staff uploads data
      • Scientist works with dataset
      • Metadata
    • Developer's guide
      • Metadata generation
      • ARIA integration
Powered by GitBook
On this page
  • Working with WEBDAV
  • Bash, CURL
  • Python
  • Javascript [Draft]
  • .NET [Draft]
  • Java [Draft]
  • References:
  1. Virtual Folder
  2. Integration guide

Working with WEBDAV

PreviousSelect File or Dir from Virtual FolderNextEmbedding Virtual Folder Component

Last updated 7 years ago

Working with WEBDAV

West-Life File picker and Upload-Dir picker components return URL capable of WEBDAV API which doesn't need any other type of authentication. Use this URL as confidential as possible. WEBDAV is HTTP extension, it supports basic HTTP VERBS to download file ('GET'), upload file ('PUT'), delete file ('DELETE') as well as extension to list resources ('PROPFIND') in a directory or directories. It is possible to use WEBDAV capable client application to connect to the selected folder or download selected file. Following sections contains samples how to download or upload file to Virtual Folder using WEBDAV API using scripting or compiled languages. Full samples can be downloaded

  • bash:

  • python:

Bash, CURL

Prerequisite: install curl using your OS package manager yum install curl or apt-get install curl. cURL is command-line tool for transferring data using various protocols available as standard package in most OS.

Bash script to UPLOAD file to the webdav URL

curl -X PUT [updirurl+filename] --data "any text content"

Bash script to DOWNLOAD file from the webdav URL

curl [updirurl+filename] --data "any text content"

Python

Prerequisite:

  • for Python 2.x install easywebdav using your favorite packaging system(pip install easywebdav)

  • for Python 3.x download easywebdav from .

import easywebdav;

if sys.argv[1] == 'PUT':
    url = urlparse(sys.argv[2]);
    webdav = easywebdav.connect(url.hostname,protocol=url.scheme,path=url.path);
    print("Uploading ", sys.argv[3], " to ", sys.argv[2]);
    webdav.upload(sys.argv[3], sys.argv[3]);
else:
    url = urlparse(sys.argv[1]);
    webdav = easywebdav.connect(url.hostname,protocol=url.scheme,path=url.path);
    print("Downloading ",sys.argv[2]," from ", sys.argv[1]);
    webdav.download(sys.argv[2], sys.argv[2]);

Javascript [Draft]

Not yet verified. The following code uses XMLHTTPRequest API.

function ajaxrequest(method, url, callback,contentdivid,content) {
    var request;
    // compatible with IE7+, Firefox, Chrome, Opera, Safari
    request = new XMLHttpRequest();
    request.onreadystatechange = function(){
        if (request.readyState == 4 && request.status == 200){
            callback(request.responseText,contentdivid);
        } else {
            console.log(request.response)
            alert('There was an error. See console. ');
        }
    }
    request.open(method, url, true);
    request.send(content);
}

function downloadcallback(responsetext,contentdivid) {
    document.getElementById(contentdivid).innerHTML = responsetext;
}

function uploadcallback(responsetext,contentdivid) {
    document.getElementById(contentdivid).innerHTML = "Upload OK.";
}

function downloadwebdavfile(url,contentdivid) {
    ajaxrequest("GET",url, downloadcallback,contentdivid)
}

function uploadwebdavfile(url,contentdivid,content) {
    ajaxrequest("PUT",url,uploadcallback,content)
}

.NET [Draft]

        public static string Put(string url, string filename, string content)
        {
            string log = "";
            try
            {
                // Create an HTTP request for the URL.
                HttpWebRequest httpPutRequest =
                    (HttpWebRequest) WebRequest.Create(url+'/'+filename);
                httpPutRequest.PreAuthenticate = false;                
                httpPutRequest.Method = @"PUT";                
                httpPutRequest.Headers.Add(@"Overwrite", @"T");                
                httpPutRequest.ContentLength = content.Length;                
                httpPutRequest.SendChunked = true;                
                Stream requestStream = httpPutRequest.GetRequestStream();
                requestStream.Write(
                    Encoding.UTF8.GetBytes((string) content),
                    0, content.Length);

                requestStream.Close();

                HttpWebResponse httpPutResponse =
                    (HttpWebResponse) httpPutRequest.GetResponse();                
                log += @"PUT Response: " + httpPutResponse.StatusDescription;
                return log;
            }
            catch (Exception e)
            {

                Console.WriteLine("PUT Response: Exception" + e.Message + " StackTrace:" + e.StackTrace);
                throw e;
            }

        }

Java [Draft]

In preparation.

//webdav client sample

References:

Standard class use used

HTTP Extensions for Web Distributed Authoring and Versioning (WebDAV):

XMLHttpRequest Living Standard:

easywebdav 1.2.0 A straight-forward WebDAV client, implemented using Requests

cURL,

https://gist.github.com/TomasKulhanek/c94e148159a871ee688685828da82ebd
https://gist.github.com/TomasKulhanek/9d939350d234ec43ff1ffac8d1baa1f4
Download full sample script
here
Download full sample scripts
HttpWebRequest
tools.ietf.org/html/rfc4918
https://xhr.spec.whatwg.org/
https://pypi.python.org/pypi/easywebdav
https://curl.haxx.se/docs/