node-ovh-objectstorage
Version:
Simple library to use OVH Public Cloud Object Storage.
660 lines (555 loc) • 34.1 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Home - Documentation
</title>
<link href="https://www.braintreepayments.com/images/favicon-ccda0b14.png" rel="icon" type="image/png">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
<link type="text/css" rel="stylesheet" href="styles/collapse.css">
<!-- start Mixpanel -->
<script type="text/javascript">(function(e,a){if(!a.__SV){var b=window;try{var c,l,i,j=b.location,g=j.hash;c=function(a,b){return(l=a.match(RegExp(b+"=([^&]*)")))?l[1]:null};g&&c(g,"state")&&(i=JSON.parse(decodeURIComponent(c(g,"state"))),"mpeditor"===i.action&&(b.sessionStorage.setItem("_mpcehash",g),history.replaceState(i.desiredHash||"",e.title,j.pathname+j.search)))}catch(m){}var k,h;window.mixpanel=a;a._i=[];a.init=function(b,c,f){function e(b,a){var c=a.split(".");2==c.length&&(b=b[c[0]],a=c[1]);b[a]=function(){b.push([a].concat(Array.prototype.slice.call(arguments,
0)))}}var d=a;"undefined"!==typeof f?d=a[f]=[]:f="mixpanel";d.people=d.people||[];d.toString=function(b){var a="mixpanel";"mixpanel"!==f&&(a+="."+f);b||(a+=" (stub)");return a};d.people.toString=function(){return d.toString(1)+".people (stub)"};k="disable time_event track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config reset people.set people.set_once people.increment people.append people.union people.track_charge people.clear_charges people.delete_user".split(" ");
for(h=0;h<k.length;h++)e(d,k[h]);a._i.push([b,c,f])};a.__SV=1.2;b=e.createElement("script");b.type="text/javascript";b.async=!0;b.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL?MIXPANEL_CUSTOM_LIB_URL:"file:"===e.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";c=e.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c)}})(document,window.mixpanel||[]);
mixpanel.init("1919205b2da72e4da3b9b6639b444d59");</script>
<!-- end Mixpanel -->
</head>
<body>
<svg style="display: none;">
<defs>
<symbol id="linkIcon" fill="#706d77" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"/>
</symbol>
</defs>
</svg>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<div class="top-nav-wrapper">
<ul>
<li class="active" >
<a href="index.html">
<svg fill="#0095dd" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>
</a>
</li>
</ul>
</div>
<nav>
<h3 class="reference-title">
OVH Object Storage
</h3>
<h3>Classes</h3><ul><li id="Account-nav"><a href="Account.html">Account</a><ul class='methods'><li data-type="method" id="Account-all-nav"><a href="Account.html#all">all</a></li><li data-type="method" id="Account-containers-nav"><a href="Account.html#containers">containers</a></li><li data-type="method" id="Account-details-nav"><a href="Account.html#details">details</a></li><li data-type="method" id="Account-generateKey-nav"><a href="Account.html#generateKey">generateKey</a></li><li data-type="method" id="Account-metas-nav"><a href="Account.html#metas">metas</a></li></ul></li><li id="AccountMeta-nav"><a href="AccountMeta.html">AccountMeta</a><ul class='methods'><li data-type="method" id="AccountMeta-all-nav"><a href="AccountMeta.html#all">all</a></li><li data-type="method" id="AccountMeta-create-nav"><a href="AccountMeta.html#create">create</a></li><li data-type="method" id="AccountMeta-create_with_result-nav"><a href="AccountMeta.html#create_with_result">create_with_result</a></li><li data-type="method" id="AccountMeta-delete-nav"><a href="AccountMeta.html#delete">delete</a></li><li data-type="method" id="AccountMeta-delete_with_result-nav"><a href="AccountMeta.html#delete_with_result">delete_with_result</a></li><li data-type="method" id="AccountMeta-get-nav"><a href="AccountMeta.html#get">get</a></li><li data-type="method" id="AccountMeta-has-nav"><a href="AccountMeta.html#has">has</a></li><li data-type="method" id="AccountMeta-update-nav"><a href="AccountMeta.html#update">update</a></li><li data-type="method" id="AccountMeta-update_with_result-nav"><a href="AccountMeta.html#update_with_result">update_with_result</a></li></ul></li><li id="Containers-nav"><a href="Containers.html">Containers</a><ul class='methods'><li data-type="method" id="Containers-create-nav"><a href="Containers.html#create">create</a></li><li data-type="method" id="Containers-create_with_result-nav"><a href="Containers.html#create_with_result">create_with_result</a></li><li data-type="method" id="Containers-delete-nav"><a href="Containers.html#delete">delete</a></li><li data-type="method" id="Containers-delete_objects-nav"><a href="Containers.html#delete_objects">delete_objects</a></li><li data-type="method" id="Containers-delete_objects_with_result-nav"><a href="Containers.html#delete_objects_with_result">delete_objects_with_result</a></li><li data-type="method" id="Containers-delete_with_result-nav"><a href="Containers.html#delete_with_result">delete_with_result</a></li><li data-type="method" id="Containers-exist-nav"><a href="Containers.html#exist">exist</a></li><li data-type="method" id="Containers-info-nav"><a href="Containers.html#info">info</a></li><li data-type="method" id="Containers-list-nav"><a href="Containers.html#list">list</a></li><li data-type="method" id="Containers-metas-nav"><a href="Containers.html#metas">metas</a></li></ul></li><li id="ContainersMeta-nav"><a href="ContainersMeta.html">ContainersMeta</a><ul class='methods'><li data-type="method" id="ContainersMeta-all-nav"><a href="ContainersMeta.html#all">all</a></li><li data-type="method" id="ContainersMeta-create-nav"><a href="ContainersMeta.html#create">create</a></li><li data-type="method" id="ContainersMeta-create_with_result-nav"><a href="ContainersMeta.html#create_with_result">create_with_result</a></li><li data-type="method" id="ContainersMeta-delete-nav"><a href="ContainersMeta.html#delete">delete</a></li><li data-type="method" id="ContainersMeta-delete_with_result-nav"><a href="ContainersMeta.html#delete_with_result">delete_with_result</a></li><li data-type="method" id="ContainersMeta-get-nav"><a href="ContainersMeta.html#get">get</a></li><li data-type="method" id="ContainersMeta-has-nav"><a href="ContainersMeta.html#has">has</a></li><li data-type="method" id="ContainersMeta-update-nav"><a href="ContainersMeta.html#update">update</a></li><li data-type="method" id="ContainersMeta-update_with_result-nav"><a href="ContainersMeta.html#update_with_result">update_with_result</a></li></ul></li><li id="Objects-nav"><a href="Objects.html">Objects</a><ul class='methods'><li data-type="method" id="Objects-copy-nav"><a href="Objects.html#copy">copy</a></li><li data-type="method" id="Objects-copy_with_result-nav"><a href="Objects.html#copy_with_result">copy_with_result</a></li><li data-type="method" id="Objects-delete-nav"><a href="Objects.html#delete">delete</a></li><li data-type="method" id="Objects-delete_with_result-nav"><a href="Objects.html#delete_with_result">delete_with_result</a></li><li data-type="method" id="Objects-deletes-nav"><a href="Objects.html#deletes">deletes</a></li><li data-type="method" id="Objects-deletes_with_result-nav"><a href="Objects.html#deletes_with_result">deletes_with_result</a></li><li data-type="method" id="Objects-download-nav"><a href="Objects.html#download">download</a></li><li data-type="method" id="Objects-exist-nav"><a href="Objects.html#exist">exist</a></li><li data-type="method" id="Objects-expire_after-nav"><a href="Objects.html#expire_after">expire_after</a></li><li data-type="method" id="Objects-expire_after_with_result-nav"><a href="Objects.html#expire_after_with_result">expire_after_with_result</a></li><li data-type="method" id="Objects-expire_at-nav"><a href="Objects.html#expire_at">expire_at</a></li><li data-type="method" id="Objects-expire_at_with_result-nav"><a href="Objects.html#expire_at_with_result">expire_at_with_result</a></li><li data-type="method" id="Objects-get-nav"><a href="Objects.html#get">get</a></li><li data-type="method" id="Objects-getTempLink-nav"><a href="Objects.html#getTempLink">getTempLink</a></li><li data-type="method" id="Objects-info-nav"><a href="Objects.html#info">info</a></li><li data-type="method" id="Objects-metas-nav"><a href="Objects.html#metas">metas</a></li><li data-type="method" id="Objects-save-nav"><a href="Objects.html#save">save</a></li><li data-type="method" id="Objects-save_with_result-nav"><a href="Objects.html#save_with_result">save_with_result</a></li><li data-type="method" id="Objects-saveData-nav"><a href="Objects.html#saveData">saveData</a></li><li data-type="method" id="Objects-saveFile-nav"><a href="Objects.html#saveFile">saveFile</a></li><li data-type="method" id="Objects-set-nav"><a href="Objects.html#set">set</a></li><li data-type="method" id="Objects-set_with_result-nav"><a href="Objects.html#set_with_result">set_with_result</a></li></ul></li><li id="ObjectsMeta-nav"><a href="ObjectsMeta.html">ObjectsMeta</a><ul class='methods'><li data-type="method" id="ObjectsMeta-all-nav"><a href="ObjectsMeta.html#all">all</a></li><li data-type="method" id="ObjectsMeta-create-nav"><a href="ObjectsMeta.html#create">create</a></li><li data-type="method" id="ObjectsMeta-create_with_result-nav"><a href="ObjectsMeta.html#create_with_result">create_with_result</a></li><li data-type="method" id="ObjectsMeta-delete-nav"><a href="ObjectsMeta.html#delete">delete</a></li><li data-type="method" id="ObjectsMeta-delete_with_result-nav"><a href="ObjectsMeta.html#delete_with_result">delete_with_result</a></li><li data-type="method" id="ObjectsMeta-get-nav"><a href="ObjectsMeta.html#get">get</a></li><li data-type="method" id="ObjectsMeta-has-nav"><a href="ObjectsMeta.html#has">has</a></li><li data-type="method" id="ObjectsMeta-update-nav"><a href="ObjectsMeta.html#update">update</a></li><li data-type="method" id="ObjectsMeta-update_with_result-nav"><a href="ObjectsMeta.html#update_with_result">update_with_result</a></li></ul></li><li id="OVHStorage-nav"><a href="OVHStorage.html">OVHStorage</a><ul class='methods'><li data-type="method" id="OVHStorage-account-nav"><a href="OVHStorage.html#account">account</a></li><li data-type="method" id="OVHStorage-connection-nav"><a href="OVHStorage.html#connection">connection</a></li><li data-type="method" id="OVHStorage-containers-nav"><a href="OVHStorage.html#containers">containers</a></li><li data-type="method" id="OVHStorage-getConnectionDetails-nav"><a href="OVHStorage.html#getConnectionDetails">getConnectionDetails</a></li><li data-type="method" id="OVHStorage-objects-nav"><a href="OVHStorage.html#objects">objects</a></li></ul></li></ul><h3 id="global-nav"><a href="global.html">Global</a></h3>
</nav>
<div id="main">
<section class="readme">
<article>
<h1>ObjectStorage OVH</h1>
<p><img src="https://img.shields.io/github/package-json/v/dimer47/node-ovh-objectstorage?color=red&style=flat-square" alt="Release : 2.0 "> <img src="https://img.shields.io/github/last-commit/dimer47/node-ovh-objectstorage?color=yellow&label=Last%20update&style=flat-square" alt="Last update"> <img src="https://img.shields.io/bundlephobia/minzip/node-ovh-objectstorage?color=green&label=dependency%20size&style=flat-square" alt="Dependency size"> <img src="https://img.shields.io/github/repo-size/dimer47/node-ovh-objectstorage?style=flat-square" alt="Repo size"> <img src="https://img.shields.io/npm/dt/node-ovh-objectstorage?style=flat-square" alt="Downloads"> <img src="https://img.shields.io/github/license/dimer47/node-ovh-objectstorage?style=flat-square" alt="License"></p>
<p>Simple library to use OVH Public Cloud Object Storage. <br> <br><br>
Create and manage containers (public, private or static), add and manage objects in OVH Public Cloud (OpenStack).</p>
<p><strong>Based on</strong> <a href="https://developer.openstack.org/api-ref/object-storage/?expanded=">developer.openstack.org</a> official<br>
documentation.</p>
<p>A complete JSDoc is<br>
available <a href="https://htmlpreview.github.io/?https://raw.githubusercontent.com/dimer47/node-ovh-objectstorage/master/doc/index.html">here</a><br>
.<br>
<br></p>
<p><strong>⚠️ Warning :</strong> This version introduces <code>some breakpoints</code>, if you want to use this version, it's recommended to<br>
refactoring all your projects. <br><br>
To use the previous version (V1), go<br>
on <a href="https://github.com/dimer47/node-ovh-objectstorage/releases/tag/v1.0.2">#v1.0.x branch</a>.</p>
<h2>🎉 Features</h2>
<ul>
<li>Get account details and manage metas (create, update, has, get or delete),</li>
<li>Create, list, get details or delete containers,</li>
<li>Check if object exist in a container,</li>
<li>Define metas (create, update, has, get or delete) for container,</li>
<li>List files on a container,</li>
<li>Import object on container</li>
<li>Download or get content of object,</li>
<li>Delete all object in containers,</li>
<li>Program automatic delete of an object on datetime or after seconds,</li>
<li>Manage metas on objects (create, update, has, get or delete).</li>
</ul>
<h2>📍 Install via npm</h2>
<pre class="prettyprint source lang-sh"><code>npm install node-ovh-objectstorage --save
</code></pre>
<h2>🧮 Examples :</h2>
<h3>Authentification</h3>
<p>Requesting a token to make operations on container.</p>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
username: '******',
password: '******',
authURL: 'https://auth.cloud.ovh.net/v3/auth',
tenantId: '******',
key: "Temporary key (optional), for generate temporary download link",
region: 'SBG'
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
} catch (e) {
// throw e
}
})();
</code></pre>
<h3>Account</h3>
<p>Available methods :</p>
<ul>
<li><strong>all()</strong> <em>: Object of account details and list containers (Promise)</em></li>
<li><strong>details()</strong> <em>: Object (Promise)</em></li>
<li><strong>containers()</strong> <em>: Array of each container object (Promise)</em></li>
<li><strong>generateKey()</strong> <em>: Array with key and header response object (Promise)</em></li>
<li><strong>metas()</strong>
<ul>
<li><strong>create(</strong> container, key, value <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>create_with_result(</strong> container, key, value <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>update(</strong> container, key, value <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>update_with_result(</strong> container, key, value <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>delete(</strong> container, key <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>delete_with_result(</strong> container, key <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>all(</strong> container <strong>)</strong> <em>: Object of metas (Promise)</em></li>
<li><strong>has(</strong> container, key <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>get(</strong> container, key <strong>)</strong> <em>: String or null (Promise)</em></li>
</ul>
</li>
</ul>
<h4>Get account details and list containers</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
// account details and list containers
await storage.account().all();
// or only account details
await storage.account().details();
// or only containers list
await storage.account().containers();
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Generate key for download file as temporary url</h4>
<p>ℹ️️ You can define the key directly in the configuration and not generate a key with this method. The key must be in the<br>
Hexadecimal SHA1 format.</p>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
// account details and list containers
let {key, headers} = await storage.account().generateKey();
// IMPORTANT : you can save key in the configuration to avoid regenerating it and also avoid losing the temporary links already generated.
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Meta information of account</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
// list all metas of container
await storage.account().metas().all("assets");
// create a new meta author
await storage.account().metas().create("assets", "author", "me");
// retrieve value of author meta
console.log(await storage.account().metas().get("assets", "author"));
// update value of author meta
await storage.account().metas().update("assets", "author", 'unknown');
// if meta author exist on container name "assets", remove it
if (await storage.account().metas().has("assets", "author"))
await storage.account().metas().delete("assets", "author");
} catch (e) {
// throw e
}
})();
</code></pre>
<h3>Containers</h3>
<p>Available methods :</p>
<ul>
<li><strong>create(</strong> container, types, web_content_pages <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>create_with_result(</strong> container, types, web_content_pages <strong>)</strong> <em>: Boolean</em></li>
<li><strong>list(</strong> container <strong>)</strong> <em>: Object (Promise)</em></li>
<li><strong>exist(</strong> container <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>info(</strong> container <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>delete_objects(</strong> container <strong>)</strong> <em>: Object (Promise)</em></li>
<li><strong>delete_objects_with_result(</strong> container <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>delete(</strong> container, force=false <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>delete_with_result(</strong> container, force=false <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>metas()</strong>
<ul>
<li><strong>create(</strong> container, key, value <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>create_with_result(</strong> container, key, value <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>update(</strong> container, key, value <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>update_with_result(</strong> container, key, value <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>delete(</strong> container, key <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>delete_with_result(</strong> container, key <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>all(</strong> container <strong>)</strong> <em>: Object of metas (Promise)</em></li>
<li><strong>has(</strong> container, key <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>get(</strong> container, key <strong>)</strong> <em>: String or null (Promise)</em></li>
</ul>
</li>
</ul>
<h4>Create</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.containers().create("private-files");
await storage.containers().create("assets", "static", {
index: 'index.html',
css: 'style.css',
error: 'error.html',
});
// or with boolean result
console.log(await storage.containers().create_with_result("images", "public"));
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Delete</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.containers().delete("assets");
// or with boolean result
console.log(await storage.containers().delete_with_result("images"));
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Delete (container and all objects inside)</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.containers().delete("assets", true);
// or with boolean result
console.log(await storage.containers().delete_with_result("images", true));
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Remove all object in container</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.containers().delete_objects("assets");
// or with boolean result
console.log(await storage.containers().delete_objects_with_result("images"));
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>List all object in container</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
let objects = await storage.containers().list("assets");
console.log(objects);
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Check if container exist</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
if (await storage.containers().exist("assets"))
console.log("Assets container exist !");
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Details about container</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
let details = await storage.containers().info("assets");
console.log(details);
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Meta information of container</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
// list all metas of container
await storage.containers().metas().all("assets");
// create a new meta author
await storage.containers().metas().create("assets", "author", "me");
// retrieve value of author meta
console.log(await storage.containers().metas().get("assets", "author"));
// update value of author meta
await storage.containers().metas().update("assets", "author", 'unknown');
// if meta author exist on container name "assets", remove it
if (await storage.containers().metas().has("assets", "author"))
await storage.containers().metas().delete("assets", "author");
} catch (e) {
// throw e
}
})();
</code></pre>
<h3>Objects</h3>
<ul>
<li><strong>save(</strong> file, path <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>save_with_result(</strong> file, path <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>set(</strong> file, path <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>set_with_result(</strong> file, path <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>exist(</strong> path <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>info(</strong> path <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>get(</strong> path <strong>)</strong> <em>: Object with content and header response (Promise)</em></li>
<li><strong>getTempLink(</strong> path, validityDurationInSeconds, checkContainer = true <strong>)</strong> <em>: Temporary download URL (Promise)</em></li>
<li><strong>download(</strong> path, pathLocal <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>copy(</strong> pathOrigin, pathToPaste <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>copy_with_result()</strong> <em>: Boolean (Promise)</em></li>
<li><strong>delete(</strong> path, checkContainer = true <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>delete_with_result(</strong> path, checkContainer = true <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>deletes(</strong> path, checkContainer = true <strong>)</strong> <em>: Header response of all deleted files (Promise)</em></li>
<li><strong>deletes_with_result(</strong> path, checkContainer = true <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>expire_at(</strong> path, expire_date <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>expire_at_with_result(</strong> path, expire_date <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>expire_after(</strong> path, delete_seconds <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>expire_after_with_result(</strong> path, delete_seconds <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>metas()</strong>
<ul>
<li><strong>create(</strong> path, key, value <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>create_with_result(</strong> path, key, value <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>update(</strong> path, key, value <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>update_with_result(</strong> path, key, value <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>delete(</strong> path, key <strong>)</strong> <em>: Header response (Promise)</em></li>
<li><strong>delete_with_result(</strong> path, key <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>all(</strong> path <strong>)</strong> <em>: Object of metas (Promise)</em></li>
<li><strong>has(</strong> path, key <strong>)</strong> <em>: Boolean (Promise)</em></li>
<li><strong>get(</strong> path, key <strong>)</strong> <em>: String or null (Promise)</em></li>
</ul>
</li>
</ul>
<h4>Download object</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.objects().download("/assets/IMG_1145.jpg", "./IMG_1145.jpg")
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Get object content</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
let rqt = await storage.objects().get("/assets/IMG_1145.jpg");
console.log(rqt.content);
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Get temporary download object url</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.account().generateKey(); // if you have not defined a key in the configurations
let url = await storage.objects().getTempLink("/assets/IMG_1145.jpg", 60 * 60); // expire after 1h
console.log(url);
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Add object</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.objects().save("./IMG_1145.jpg", "/assets/IMG_1145.jpg")
// or with boolean result
console.log(await storage.objects().save_with_result("./IMG_1145.jpg", "/assets/IMG_1145.jpg"))
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Clone object</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.objects().copy("/assets/IMG_1145.jpg", "/assets/IMG_1145_2.jpg")
// or with boolean result
console.log(await storage.objects().copy_with_result("/assets/IMG_1145.jpg", "/assets/IMG_1145_2.jpg"))
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Delete object</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.objects().delete("/assets/IMG_1145_2.jpg")
// or with boolean result
console.log(await storage.objects().delete_with_result("/assets/IMG_1145_2.jpg"))
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Details about object</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
let details = await storage.objects().info("/assets/IMG_1145.jpg")
console.log(details);
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Programming object expiration at datetime (need momentjs)</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.objects().expire_at("/assets/IMG_1145.jpg", moment().add("7", "days"))
// or with boolean result
console.log(await storage.objects().expire_at_with_result("/assets/IMG_1145.jpg", moment().add("7", "days")));
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Programming object expiration after seconds</h4>
<pre class="prettyprint source lang-javascript"><code>(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
await storage.objects().expire_after("/assets/IMG_1145.jpg", 180)
// or with boolean result
console.log(await storage.objects().expire_after_with_result("/assets/IMG_1145.jpg", 180));
} catch (e) {
// throw e
}
})();
</code></pre>
<h4>Meta information of container</h4>
<pre class="prettyprint source lang-javascript"><code>var OVHStorage = require('node-ovh-objectstorage');
var config = {
...
};
(async () => {
try {
let storage = new OVHStorage(config);
await storage.connection();
// list all metas of object
await storage.objects().metas().all("/assets/IMG_1145.jpg");
// create a new meta author
await storage.objects().metas().create("/assets/IMG_1145.jpg", "author", "me");
// retrieve value of author meta
console.log(await storage.objects().metas().get("/assets/IMG_1145.jpg", "author"));
// update value of author meta
await storage.objects().metas().update("/assets/IMG_1145.jpg", "author", 'unknown');
// if meta author exist on object, remove it
if (await storage.objects().metas().has("/assets/IMG_1145.jpg", "author"))
await storage.objects().metas().delete("/assets/IMG_1145.jpg", "author");
} catch (e) {
// throw e
}
})();
</code></pre>
<h2>🧾 License</h2>
<p><a href="LICENSE">Creative Commons Attribution Share Alike 4.0 International</a></p>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.7</a>
</footer>
<script src="scripts/linenumber.js"></script>
<script src="scripts/pagelocation.js"></script>
</body>
</html>