How to Create/Update Object Metadata in OpenStack Swift

API w/ Java


public class OpenStackSample {

  public static void main(String[] args) {
    Client client = ClientBuilder.newClient();"https://host/v1/sampleAccount/sampleBucket/sampleObject").request().header("X-Auth-Token", ...).header("X-Object-Meta-Sample-Key", "Sample Value").post(Entity.entity("", MediaType.WILDCARD_TYPE));



API w/ Go

package main

import ""

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

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/sampleAccount/sampleBucket/sampleObject' });


API w/ Python

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

API w/ Ruby

require 'rest-client' 'https://host/v1/sampleAccount/sampleBucket/sampleObject', '', :x_auth_token => ..., :x_object_meta_sample_key => 'Sample Value'


1) Configure the CLI:

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

2) Run the following command:

swift post samplebucket sampleobject -m "Sample-Key:Sample Value


from swiftclient.service import SwiftService

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

for res in'sampleBucket', [ 'sampleObject' ], { 'meta': [ 'Sample-Key:Sample Value' ] }):
  print res

Terraform Provider

1) Configure the provider:

export OS_SWAUTH=true
export OS_AUTH_URL=https://host/
export OS_USERNAME=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.

Leave a Reply

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

You are commenting using your 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.