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

OpenStack Swift API w/ Java

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;

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").post(Entity.entity("", MediaType.WILDCARD_TYPE));

    client.close();
  }

}

OpenStack Swift API w/ Go

package ociclassicsample

import "gopkg.in/resty.v1"

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

OpenStack Swift API w/ Node.js

var https = require('https');

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

req.end();

OpenStack Swift API w/ Python

import requests

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

OpenStack Swift API w/ Ruby

require 'rest-client'

RestClient.post 'https://Host/v1/sampleService-sampleIdentityDomain/sampleBucket/sampleObject', '', :x_auth_token => ..., :x_object_meta_sample_key => 'Sample Value'

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 post samplebucket sampleobject -m "Sample-Key:Sample Value

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.post('sampleBucket', [ 'sampleObject' ], { 'meta': [ 'Sample-Key:Sample Value' ] }):
  print res

OCI Classic FTM API

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

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

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

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

    ftm.setObjectMetadata("sampleBucket", "sampleObject", metadata, null);

    ftm.shutdown();
  }

}

OCI Classic FTM CLI

1) Run the following command:

java -jar ftmcli.jar set -U sampleuser -A https://host/ -S sampleservice -I sampleidentitydomain --save-auth-key -C "Sample-Key:Sample Value" samplebucket sampleobject

OCI Classic Java SDK

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.updateObjectMetadata("sampleBucket", "sampleObject", "Sample-Key", "Sample Value");
  }

}

AWS CLI

Not supported.

Terraform OCI Classic Provider

Not supported.

Terraform OpenStack Provider

1) Configure the provider:

export OS_SWAUTH=true
export OS_AUTH_URL=https://host/
export OS_USERNAME=sampleService-sampleIdentity:sampleUser
export OS_PASSWORD=samplePassword

2) Create the configuration:

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

3) Apply the change.

Terraform AWS Provider

Not supported.

s3cmd

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.