How to upload files to Object Storage containers from Linux using curl?

You can use Openstack API to upload files, first you have to generate api token with following script:

#!/bin/bash
# Example curl for token retrieve.
# Change name, domain, password in identity
# Change id and domain in project scope
# Change url corresponding to OS
# If you succeed you will recive x-subject token
curl -i \
-H "Content-Type: application/json" \
-d '
{ "auth": {
"identity": {
"methods": ["password"],
"password": {
"user": {
"name": "xxxxxxx@xxxxx.com",
"domain": { "name": "cloud_000xx" },
"password": "xxxxxxxxxxx"
    }
   }
  },
"scope": { "project": {
"id": "your_project_id",
"domain": { "id": "your_domain_id"
     }
    }
   }
  }
}'\
https://creodias.eu:5000/v3/auth/tokens ; echo 


The obtained token will be in headers, field X-Subject-Token.

example response header:

HTTP/1.1 201 Created
Date: Mon, 05 Feb 2018 11:36:38 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Subject-Token: c3830c15d9224881a2c3619c36976dd2
Vary: X-Auth-Token
x-openstack-request-id: req-7fac97c4-10e7-469c-9c8e-7ba171f8b84f
Content-Length: 6685
Content-Type: application/json

 

Then you can use curl to send file upload request.

For example:

curl -H 'X-Auth-Token: your_auth_token' https://creodias.eu:8080/swift/v1/name_of_your_container 

Will list the content of your Object Storage.

To upload a file:

curl -X PUT -i -d "" -H 'X-Auth-Token: your_auth_token'https://creodias.eu:8080/swift/v1/name_of_your_container/your_file