Software

How to Create/Update an Object in OCI Object Storage Classic

OpenStack Swift API w/ Java

W/o Metadata

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

public class OciClassicSample {

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

    client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).put(sampleFile);

    client.close();
  }

}

W/ Metadata

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

public class OciClassicSample {

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

    client.target("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).header("X-Object-Meta-Sample-Key", "Sample Value").put(sampleFile);

    client.close();
  }

}

OpenStack Swift API w/ Go

W/o Metadata

package main

import "gopkg.in/resty.v1"

func main() {
  resty.R().SetHeader("X-Auth-Token", ...).SetBody(sampleFile).Put("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject")
}

W/ Metadata

package main

import "gopkg.in/resty.v1"

func main() {
  resty.R().SetHeader("X-Auth-Token", ...).SetHeader("X-Object-Meta-Sample-Key", "Sample Value").SetBody(sampleFile).Put("https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject")
}

OpenStack Swift API w/ Node.js

W/o Metadata

const https = require('https')

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

req.write(sampleFile)

req.end()

W/ Metadata

const https = require('https')

var req = https.request({ headers: { 'x-auth-token': ..., 'x-object-meta-sample-key': 'Sample Value' }, hostname: 'host', method: 'PUT', path: '/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject' })

req.write(sampleFile)

req.end()

OpenStack Swift API w/ Python

W/o Metadata

import requests

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

W/ Metadata

import requests

requests.put('https://host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', headers = { 'X-Auth-Token': ..., 'X-Object-Meta-Sample-Key': 'Sample Value' }, data = sampleFile)

OpenStack Swift API w/ Ruby

W/o Metadata

require 'rest-client'

RestClient.put 'https://Host/v1/SampleService-SampleIdentityDomain/SampleBucket/SampleObject', SampleFile, :x_auth_token => ...

W/o Metadata

require 'rest-client'

RestClient.put 'https://Host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', SampleFile, :x_auth_token => ..., :x_container_meta_sample_key => 'Sample Value'

OpenStack Swift CLI

W/o Metadata

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 upload samplebucket samplefile --object-name sampleobject

W/ Metadata

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 upload samplebucket samplefile --object-name sampleobject -H "X-Object-Meta-Sample-Key:Sample Value"

OpenStack Swift Client

W/o Metadata

from swiftclient.service import SwiftService, SwiftUploadObject

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

for res in service.upload('sampleBucket', [ SwiftUploadObject(sampleFile, 'sampleObject') ]):
  print res

W/ Metadata

from swiftclient.service import SwiftService, SwiftUploadObject

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

for res in service.upload('sampleBucket', [ SwiftUploadObject(sampleFile, 'sampleObject') ], options = { 'header': [ 'X-Object-Meta-Sample-Key:Sample Value' ] } ):
  print res

OCI Classic FTM API

W/o Metadata

import java.io.File;

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.upload(null, "sampleBucket", "sampleObject", sampleFile);

    ftm.shutdown();
  }

}

W/ Metadata

Not supported.

OCI Classic FTM CLI

W/o Metadata

1) Run the following command:

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

W/ Metadata

Not supported.

OCI Classic Java SDK

W/o Metadata

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

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

    storage.storeObject("sampleBucket", "sampleObject", "*/*", sampleFile); // the contentType parameter will be optional in a future release
  }

}

W/ Metadata

import java.util.Map;
import java.util.HashMap;

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

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

    Map<String, String> metadata = new HashMap<String, String>();

    metadata.put("Sample-Key", "Sample Value");

    storage.storeObject("sampleBucket", "sampleObject", "*/*", metadata, sampleFile); // the contentType parameter will be optional in a future release
  }

}

AWS CLI

Not supported.

Terraform OCI Classic Provider

W/o Metadata

1) Configure the provider:

export OPC_ENDPOINT=https://host/
export OPC_IDENTITY_DOMAIN=sampleidentitydomain
export OPC_USERNAME=sampleuser
export OPC_PASSWORD=samplepassword

2) Create the configuration:

resource "opc_storage_object" "sampleobject" {
  name = "sampleobject"
  container = "samplebucket"
  content = samplefile
}

3) Apply the change.

W/ Metadata

Not supported.

Terraform OpenStack Provider

W/o Metadata

1) Configure the provider:

export OS_SWAUTH=true
export OS_AUTH_URL=https://host/
export OS_USERNAME=sampleservice-sampleidentitydomain:sampleuser
export OS_PASSWORD=samplepassword

2) Create the configuration:

resource "openstack_objectstorage_object_v1" "sampleobject" {
  name = "sampleobject"
  container_name = "samplebucket"
  content = samplefile
}

3) Apply the change.

W/ Metadata

1) Configure the provider:

export OS_SWAUTH=true
export OS_AUTH_URL=https://host/
export OS_USERNAME=sampleservice-sampleidentitydomain:sampleuser
export OS_PASSWORD=samplepassword

2) Create the configuration:

resource "openstack_objectstorage_object_v1" "sampleobject" {
  name = "sampleobject"
  container_name = "samplebucket"
  content = samplefile
  metadata {
    Sample-Key = "Sample Value"
  }
}

3) Apply the change.

Terraform AWS Provider

W/o Metadata

1) Configure the provider:

provider "aws" {
  endpoints {
    s3 = "https://host/"
  }
  access_key = "sampleservice-sampleidentitydomain"
  secret_key = "samplesecretaccesskey"
  region = "us-east-1" # ignored
  skip_credentials_validation = true
  s3_force_path_style = true
}

2) Create the configuration:

resource "aws_s3_bucket_object" "sampleobject" {
  key = "sampleobject"
  bucket = "samplebucket"
  source = "sampleFile"
}

3) Apply the change.

W/ Metadata

Not supported.

s3cmd

W/o Metadata

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 put samplefile s3://samplebucket

W/ Metadata

Not supported.

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.