In this article you will learn how to initialize and configure dhtmlxVault. Follow these simple steps:
index.html
<!DOCTYPE html>
<html>
<head>
<title>How to Start with dhtmlxVault</title>
<script type="text/javascript" src="/codebase/vault.js"></script>
<link rel="stylesheet" type="text/css" href="/codebase/vault.css">
</head>
<body>
<div id="vault"></div>
<script> // creating dhtmlxVault
var vault = new dhx.Vault("vault",{
uploader:{
target: "/upload"
}
});
</script>
</body>
</html>
Download the package and unpack it into a folder of your project.
To create dhtmlxVault, you need to include 2 source files on your page:
Make sure that you set correct relative paths to these files:
index.html
<script type="text/javascript" src="codebase/vault.js"></script>
<link rel="stylesheet" href="codebase/vault.css">
The structure of the Vault pack is the following:
dhtmlxVault makes use of Google Fonts for the elements content. That's why you need to include the related source file into your document as well:
<script type="text/javascript" src="codebase/vault.js"></script>
<link rel="stylesheet" href="codebase/vault.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,500" rel="stylesheet">
Add a container for the vault and give it an id, for example "vault":
index.html
<div id="vault"></div>
Initialize dhtmlxVault with the dhx.Vault
object constructor. The constructor has two parameters:
index.html
// creating dhtmlxVault
var vault = new dhx.Vault("vault",{// config options});
You need to set an URL to the server-side script that will process file upload before the Vault initialization. For this, specify the path as a string value of the target property in the Uploader configuration object:
index.html
// creating dhtmlxVault
var vault = new dhx.Vault('vault',{
uploader:{
target:"/upload"
}
});
Related sample: Vault. Initialization
This is the list of properties that you can specify in the Vault configuration object:
You can set necessary configuration options during initialization as the second parameter of the constructor:
var vault1 = new dhx.Vault("vault1", {
uploader:{
target:"/upload"
}
mode:"grid"
});
There are also configuration properties that are set via the Uploader configuration object:
// creating dhtmlxVault
var vault = new dhx.Vault("vault",{
uploader:{
target:"/upload"
autosend:false
}
});
More details are given in the dhtmlxVault API reference.
Related sample: Vault. Grid mode
You can load the list of files added for upload, process files uploading on the server side and configure their downloding. Check the Loading List of Files and Uploading Files articles for details.
It is possible to load a list of files from an external file with the load method or use the parse method to load a list of files from a local source.
// load from an external file
vault.data.load("/files.json");
// load from a local source
vault.data.parse(files);
dhtmlxVault accepts data in the JSON format. For example:
var files = [
{
"name":"one.jpg",
"size":36484,
},
{
"name":"another.svg",
"size":35523213
}
];
The file object has the following properties:
The path attribute is added only to files that were added in a folder. Thus, a file "dog.jpg" added in the folder "animals" will get the attribute path="animals/".
Back to top