Constructor
new OVHStorage(config)
Parameters:
Name | Type | Description |
---|---|---|
config |
OVHStorageConfig |
Define OVH Storage access configuration (endpoint, credentials, ...) |
Properties:
Name | Type | Description |
---|---|---|
config |
Object |
Connexion parameters to OVH Object Storage |
token |
string |
Token negotiate on connexion to call Object Storage API |
endpoint |
string |
Endpoint to call OVH Object Storage |
connected_at |
moment |
Moment object with datetime connexion |
- Source:
Example
let OVHStorage = require('node-ovh-objectstorage');
let config = {
username: '************',
password: '*****************************',
authURL: 'https://auth.cloud.ovh.net/v3/auth',
tenantId: '************************************',
region: 'SBG',
debug: false
};
let storage = new OVHStorage(config);
Methods
account() → {Account}
Get account manager
- Source:
Example
try {
await storage.connection();
// list details of account
console.log(await storage.account().details());
// list all containers
console.log(await storage.account().containers());
// manage metas
console.log(await storage.account().metas().all())
await storage.account().metas().create("test", 'Hello world !');
console.log(await storage.account().metas().has("test"));
console.log(await storage.account().metas().get("test"));
await storage.account().metas().update("test", 'Bye bye ...');
if(!await storage.account().metas().delete_with_result("test"))
console.log("An error has occurred when trying delete test meta on account.");
} catch (e) {
// throw error
}
(async) connection() → {Promise.<(boolean|Error)>}
Initialize connection to OVH Object Storage server
- Source:
containers() → {Containers}
Get container manager
- Source:
Example
try {
await storage.connection();
// create containers
await storage.containers().create_with_result("files-private");
await storage.containers().create_with_result("files", "public");
await storage.containers().create_with_result("files-web", "static");
// list all containers on account
console.log(await storage.account().containers());
// if container "files" exist, list all objects inside
if(await storage.containers().exist("files"))
console.log(await storage.containers().list("files"));
// get information about container "files"
console.log(await storage.containers().info("files"));
// manage metas of container "files"
console.log(await storage.containers().metas().all('files'))
await storage.containers().metas().create("files", "last-update", '2020-05-20 13:10:03');
console.log(await storage.containers().metas().has("files", "last-update"));
console.log(await storage.containers().metas().get("files", "last-update"));
if(!await storage.containers().metas().update_with_result("files", "last-update", '2020-05-20 16:41:54'))
console.log("An error has occurred when trying update last-update meta.");
} catch (e) {
// throw error
}
(async) getConnectionDetails() → {Object}
Return connection details : token, endpoints, start connection timestamp
- Source:
Example
try {
await storage.connection();
console.log(storage.getConnectionDetails());
} catch (e) {
// throw error
}
objects() → {Objects}
Get object storage manager
- Source:
Example
try {
await storage.connection();
// create containers
await storage.containers().create_with_result("pictures");
// save file on container
if (!await storage.object().save_with_result("./IMG_1145.jpg", "/pictures/IMG_1145.jpg"))
console.log("Cannot upload image file : IMG_1145.jpg.");
// create a copies of file uploaded
await storage.object().copy("pictures/IMG_1145.jpg", "/pictures/IMG_1145-2.jpg";
await storage.object().copy("pictures/IMG_1145.jpg", "/private/pictures/IMG_1145-3.jpg";
// get information about an object
console.log(await storage.object().info("/pictures/IMG_1145-2.jpg"));
// if file object exist, delete it
if(await storage.object().exist("/pictures/IMG_1145-2.jpg"))
await storage.object().delete("/pictures/IMG_1145-2.jpg")
// program expire file after 60 seconds (1 minute)
await storage.object().expire_after_with_result("/pictures/IMG_1145.jpg", 60);
await storage.object().expire_at_with_result("/private/pictures/IMG_1145-3.jpg", moment().add("2", "days"));
// manage metas of pictures
console.log(await storage.containers().metas().all("/private/pictures/IMG_1145-3.jpg"))
await storage.containers().metas().create("/private/pictures/IMG_1145-3.jpg", "last-update", '2020-05-20 13:10:03');
console.log(await storage.containers().metas().has("/private/pictures/IMG_1145-3.jpg", "last-update"));
console.log(await storage.containers().metas().get("/private/pictures/IMG_1145-3.jpg", "last-update"));
if(!await storage.containers().metas().update_with_result("/private/pictures/IMG_1145-3.jpg", "last-update", '2020-05-20 16:41:54'))
console.log("An error has occurred when trying update last-update meta.");
} catch (e) {
// throw error
}