How to Get Storage Information - Cloud APIs Cloud storage allows keeping and retrieving data worldwide at any time. You can use storage for various scenarios, including storing data for archival or disaster recovery.
Aspose.HTML Cloud provides a set of functions to work with objects uploaded to Aspose.HTML Cloud Storage or any other Cloud Storage of your choice. This section provides a description of SDK methods and REST API storage-wide operations using Aspose.HTML Cloud API v.4.0. You find out how to get user associated cloud storage information such as disc usage, object existence, etc.
Aspose.HTML Cloud SDKs and REST API allow you to incorporate Aspose.HTML Cloud services in your applications quickly and easily. SDKs are available in C #, PHP, Perl, Android, Swift, Java, and other languages to help developers speed up development.
Examples All storage access methods are divided into three groups: storage information methods, directory manipulation methods and file manipulation methods. Let’s consider a few examples that allow you to get storage information.
Example 1: How to check if the storage exists
C# ExistsAsync() method checks if specified cloud storage exists or is available for the user.
// Initialize an SDK API object
var api = new HtmlApi ( "CLIENT_ID" , "CLIENT_SECRET" ). StorageApi ;
// Check if the storage exists
var exists = await api . ExistsAsync ( "STORAGE_NAME" );
Java Configuration . setAPI_KEY ( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
Configuration . setAPP_SID ( "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" );
StorageApi storageApi = new ApiClient (). createService ( StorageApi . class );
Call < StorageExist > call = storageApi . storageExists ( "STORAGE_NAME" );
Response < StorageExist > res = call . execute ();
StorageExist result = res . body ();
C++ #include "AsposeHtmlCloud.h"
const utility :: string_t clientId = L "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ;
const utility :: string_t clientSecret = L "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ;
const utility :: string_t basePath = L "https://api.aspose.cloud/v4.0" ;
const utility :: string_t authPath = L "https://api.aspose.cloud/connect/token" ;
// Create configuration for authorization
std :: shared_ptr < ApiConfiguration > apiConfig ( new ApiConfiguration ( clientId , clientSecret , basePath , authPath ));
// Create client from configuration
std :: shared_ptr < ApiClient > apiClient ( new ApiClient ( apiConfig ));
// Create StorageApi
StorageApi * api = new StorageApi ( apiClient );
utility :: string_t storage = L "StorageName" ;
auto result = api -> storageExists ( storage ). get ();
bool exist = result -> isExists ();
delete api ;
Python configuration = Configuration (
basePath = "https://api.aspose.cloud/v4.0" ,
authPath = "https://api.aspose.cloud/connect/token" ,
apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
debug = True )
client = Client ( configuration )
api = StorageApi ( client )
res = api . storage_exists ( "StorageName" )
res = res . to_dict ()
exist = res [ 'exists' ]
print ( res )
PHP $configuration = array (
"basePath" => "https://api.aspose.cloud/v4.0" ,
"authPath" => "https://api.aspose.cloud/connect/token" ,
"apiKey" => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
"appSID" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
"defaultUserAgent" => "Webkit"
);
$api_stor = new StorageApi ( $configuration );
$result = $api_stor -> storageExists ( "StorageName" );
$isExist = $result -> getExists ();
Ruby # load the gem
require 'aspose_html_cloud'
CONFIG = {
"basePath" : "https://api.aspose.cloud/v4.0" ,
"authPath" : "https://api.aspose.cloud/connect/token" ,
"apiKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
"appSID" : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
"debug" : true
}
api = AsposeHtml :: StorageApi . new CONFIG
res = api . storage_exists ( 'storage_name' )
exist = res . exists
Node.js // Get keys from aspose site.
// There is free quota available.
// For more details, see https://purchase.aspose.cloud/pricing
var conf = {
"basePath" : "https://api.aspose.cloud/v4.0" ,
"authPath" : "https://api.aspose.cloud/connect/token" ,
"apiKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
"appSID" : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
"defaultUserAgent" : "NodeJsWebkit"
};
var api = require ( '@asposecloud/aspose-html-cloud' );
// Create Storage Api object
var instance = new api . StorageApi ( conf );
var callback = function ( error , data , response ) {
if ( error ) {
console . error ( error );
} else {
console . log ( data );
}
};
instance . storageExists ( 'storage_name' , callback );
Swift import Alamofire
import Foundation
import XCTest
import AsposeHtmlCloud
ClientAPI . setConfig (
basePath : "https://api.aspose.cloud/v4.0" ,
authPath : "https://api.aspose.cloud/connect/token" ,
apiKey : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
appSID : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
debugging : true
)
let expectation = self . expectation ( description : "Test is exist storage" )
let storage = "StorageName"
StorageAPI . storageExists ( storageName : storage ) {( data , error ) in
guard error == nil else {
XCTFail ( "Error get is storage exist. Error= \( error !. localizedDescription ) " )
return
}
XCTAssertTrue ( data !. exists )
expectation . fulfill ()
}
self . waitForExpectations ( timeout : 100.0 , handler : nil )
Java/Android Configuration . setAPI_KEY ( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
Configuration . setAPP_SID ( "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" );
StorageApi storageApi = new ApiClient (). createService ( StorageApi . class );
Call < StorageExist > call = storageApi . storageExists ( "STORAGE_NAME" );
Response < StorageExist > res = call . execute ();
StorageExist result = res . body ();
CURL curl -X POST -v \
"https://api.aspose.cloud/v4.0/html/storage/exists/storage?storageName=STORAGE_NAME" \
-H "Content-Type: application/json" \
-H "Authorization:Bearer <JWT_token>"
Example 2: How to get the storage disc usage
C# // Initialize an SDK API object
var api = new HtmlApi ( "CLIENT_ID" , "CLIENT_SECRET" ). StorageApi ;
// Get storage information by specified storage name, including total and used disc space
var exists = await api . GetStorageAsync ( "STORAGE_NAME" );
Java Configuration . setAPI_KEY ( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
Configuration . setAPP_SID ( "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" );
StorageApi storageApi = new ApiClient (). createService ( StorageApi . class );
Call < DiscUsage > call = storageApi . getDiscUsage ( null );
Response < DiscUsage > res = call . execute ();
DiscUsage result = res . body ();
C++ #include "AsposeHtmlCloud.h"
const utility :: string_t clientId = L "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ;
const utility :: string_t clientSecret = L "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ;
const utility :: string_t basePath = L "https://api.aspose.cloud/v4.0" ;
const utility :: string_t authPath = L "https://api.aspose.cloud/connect/token" ;
// Create configuration for authorization
std :: shared_ptr < ApiConfiguration > apiConfig ( new ApiConfiguration ( clientId , clientSecret , basePath , authPath ));
// Create client from configuration
std :: shared_ptr < ApiClient > apiClient ( new ApiClient ( apiConfig ));
// Create StorageApi
StorageApi * api = new StorageApi ( apiClient );
utility :: string_t storage = L "StorageName" ;
auto result = api -> getDiscUsage ( storage ). get ();
int64_t total = result -> getTotalSize ();
int64_t used = result -> getUsedSize ();
delete api ;
Python configuration = Configuration (
basePath = "https://api.aspose.cloud/v4.0" ,
authPath = "https://api.aspose.cloud/connect/token" ,
apiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
appSid = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
debug = True )
client = Client ( configuration )
api = StorageApi ( client )
# default storage
res = api . get_disc_usage () . to_dict ()
total_size = res [ 'total_size' ]
used_size = res [ 'used_size' ]
print ( res )
PHP $configuration = array (
"basePath" => "https://api.aspose.cloud/v4.0" ,
"authPath" => "https://api.aspose.cloud/connect/token" ,
"apiKey" => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
"appSID" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
"defaultUserAgent" => "Webkit"
);
$api_stor = new StorageApi ( $configuration );
// Default storage
$storage_name = null ;
$result = $api_stor -> getDiscUsage ( $storage_name );
$used = $result -> getUsedSize ();
$total = $result -> getTotalSize ();
Ruby # load the gem
require 'aspose_html_cloud'
CONFIG = {
"basePath" : "https://api.aspose.cloud/v4.0" ,
"authPath" : "https://api.aspose.cloud/connect/token" ,
"apiKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
"appSID" : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
"debug" : true
}
api = AsposeHtml :: StorageApi . new CONFIG
opts = { storage_name : nil }
res = api . get_disc_usage ( opts )
used = res . used_size
total = res . total_size
Node.js // Get keys from aspose site.
// There is free quota available.
// For more details, see https://purchase.aspose.cloud/pricing
var conf = {
"basePath" : "https://api.aspose.cloud/v4.0" ,
"authPath" : "https://api.aspose.cloud/connect/token" ,
"apiKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
"appSID" : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
"defaultUserAgent" : "NodeJsWebkit"
};
var api = require ( '@asposecloud/aspose-html-cloud' );
// Create Storage Api object
var instance = new api . StorageApi ( conf );
var callback = function ( error , data , response ) {
if ( error ) {
console . error ( error );
} else {
console . log ( data );
}
};
var opts = { 'storageName' : null };
instance . getDiscUsage ( opts , callback );
Swift import Alamofire
import Foundation
import XCTest
import AsposeHtmlCloud
ClientAPI . setConfig (
basePath : "https://api.aspose.cloud/v4.0" ,
authPath : "https://api.aspose.cloud/connect/token" ,
apiKey : "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ,
appSID : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ,
debugging : true
)
let expectation = self . expectation ( description : "TestDiscUsage" )
StorageAPI . getDiscUsage ( storageName : nil ){( data , error ) in
guard error == nil else {
XCTFail ( "Error get discUsage. Error= \( error !. localizedDescription ) " )
return
}
XCTAssertTrue ( data !. totalSize > 0 )
XCTAssertTrue ( data !. usedSize > 0 )
expectation . fulfill ()
}
self . waitForExpectations ( timeout : 100.0 , handler : nil )
Java/Android Configuration . setAPI_KEY ( "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
Configuration . setAPP_SID ( "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" );
StorageApi storageApi = new ApiClient (). createService ( StorageApi . class );
Call < DiscUsage > call = storageApi . getDiscUsage ( null );
Response < DiscUsage > res = call . execute ();
DiscUsage result = res . body ();
CURL curl -X POST -v \
"https://api.aspose.cloud/v4.0/html/storage/disc/usage?storageName=STORAGE_NAME" \
-H "Content-Type: application/json" \
-H "Authorization:Bearer <JWT_token>"