How to Retrieve an Object 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", ...).get();

    if (res.getStatus() == 200)
      out.println(res.readEntity(String.class));

    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", ...).Get("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject")

  if res.StatusCode() == 200 {
    fmt.Printf("%v\n", res)
  }

}

OpenStack Swift API w/ Node.js

var https = require('https');

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

  if (res.statusCode === 200) {
    var body = '';
 
    res.on('data', (chunk) => {
      body += chunk.toString();
    });
 
    res.on('end', () => {
      console.log(body);
    });
 
  }
 
});
 
req.end();

OpenStack Swift API w/ Python

import requests

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

if res.ok:
  print res.text

OpenStack Swift API w/ Ruby

require 'rest-client'

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

if res.code == 200
  puts res.body
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 download 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.download('sampleBucket', [ 'sampleObject' ], { 'out_file': sampleFile }):
  print res

OCI Classic FTM API

import oracle.cloudstorage.ftm.FileTransferAuth;
import oracle.cloudstorage.ftm.FileTransferManager;

public class OciClassicSample {

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

    ftm.download(null, "sampleBucket", "sampleObject", sampleFile);

    ftm.shutdown();
  }

}

OCI Classic FTM CLI

1) Run the following command:

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

OCI Classic Java SDK

import static java.lang.System.out;

import java.io.BufferedReader;
import java.io.InputStreamReader;

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

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"));

    StorageInputStream obj = storage.retrieveObject("sampleBucket", "sampleObject");

    BufferedReader in = new BufferedReader(new InputStreamReader(obj));

    in.lines().forEach(out::println);
  }

}

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 get-object --bucket samplebucket --endpoint-url https://host/ --key sampleobject samplefile

Terraform OCI Classic Provider

N/A.

Terraform OpenStack Provider

N/A.

Terraform AWS Provider

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 get 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.