How to Retrieve Object Metadata in OCI Object Storage Classic

OpenStack Swift API w/ Java

import static java.lang.System.out;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;

public class OciClassicSample {

  public static void main(String[] args) {
    Client client = ClientBuilder.newClient();

    Response res = client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).head();

    if (res.getStatus() == 200)
      res.getHeaders().forEach((k, v) -> out.println(k + " = " + v));

    client.close();
  }

}

OpenStack Swift API w/ Go

package ociclassicsample

import "gopkg.in/resty.v1"

import "fmt"

func main() {
  res, _ := resty.R().SetHeader("X-Auth-Token", ...).Head("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject")

  if res.StatusCode() == 200 {

    for k, v := range res.Header() {
      fmt.Printf("%v = %v\n", k, v)
    }

  }

}

OpenStack Swift API w/ Node.js

var https = require('https');

var req = https.request({ headers: { 'x-auth-token': ... }, hostname: 'host', method: 'HEAD', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject' }, (res) => {

  if (res.statusCode === 200)
 
    for (k in res.headers)
      console.log(k + ' = ' + res.headers[k]);

});

req.end();

OpenStack Swift API w/ Python

import requests

res = requests.head('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ... })

if res.ok:
 
  for k, v in res.headers.items():
    print k + ' = ' + v + '\n'

OpenStack Swift API w/ Ruby

require 'rest-client'

res = RestClient.head 'https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', :x_auth_token => ...

if res.code == 200
  res.headers.each {|k, v| puts "#{k} = #{v}" }
end

OpenStack Swift CLI

1) Configure the CLI:

export ST_AUTH=https://host/auth/v1.0
export ST_USER=sampleservice-sampleidentitydomain:sampleuser
export ST_KEY=samplepassword

2) Run the following command:

swift stat samplebucket sampleobject

OpenStack Swift Client

from swiftclient.service import SwiftService

service = SwiftService({ 'auth': 'https://host/auth/v1.0', 'user': 'sampleService-sampleIdentityDomain:sampleUser', 'key': 'samplePassword' })

for res in service.stat('sampleBucket', [ 'sampleObject' ]):
  print res

OCI Classic FTM API

import static java.lang.System.out;

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;
import oracle.cloudstorage.ftm.model.CloudObject;
import oracle.cloudstorage.ftm.model.ObjectMetadata;

public class OciClassicSample {

  public static void main(String[] args) {
    FileTransferManager ftm = FileTransferManager.getDefaultFileTransferManager(new FileTransferAuth("sampleUser", "samplePassword", "sampleService", "https://host/", "sampleIdentityDomain"));

    CloudObject obj = ftm.getObject("sampleBucket", "sampleObject");

    ObjectMetadata metadata = obj.getObjectMetadata();

    metadata.getCustomMetadata().forEach((k, v) -> out.println(k + " = " + v));

    ftm.shutdown();
  }

}

OCI Classic FTM CLI

1) Run the following command:

java -jar ftmcli.jar describe -U sampleuser -A https://host/ -S sampleservice -I sampleidentitydomain --save-auth-key samplebucket sampleobject

OCI Classic Java SDK

import static java.lang.System.out;

import oracle.cloud.storage.CloudStorage;
import oracle.cloud.storage.CloudStorageConfig;
import oracle.cloud.storage.CloudStorageFactory;
import oracle.cloud.storage.model.Key;

public class OciClassicSample {

  public static void main(String[] args) throws Exception {
    CloudStorage storage = CloudStorageFactory.getStorage(new CloudStorageConfig().setServiceName("sampleService-sampleIdentityDomain").setServiceUrl("https://host/").setUsername("sampleUser").setPassword("samplePassword"));

    Key obj = storage.describeObject("sampleBucket", "sampleObject");

    obj.getCustomMetadata().forEach((k, v) -> out.println(k + " = " + v));
   }

}

AWS CLI

1) Create the credentials file:

[default]
aws_access_key_id = sampleservice-sampleidentitydomain
aws_secret_access_key = samplesecretaccesskey

2) Run the following command:

aws s3api head-object --bucket samplebucket --endpoint-url https://host/ --key sampleobject

Terraform

N/A.

s3cmd

1) Create the .s3cfg file:

[default]
host_base = host
host_bucket = host
access_key = sampleservice-sampleidentitydomain
secret_key = samplesecretaccesskey

2) Run the following command:

s3cmd info s3://samplebucket/sampleobject

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.