Node.js api调用将图像上载到bluemix node js应用程序上的对象存储容器

Node.js api调用将图像上载到bluemix node js应用程序上的对象存储容器,node.js,npm,ibm-cloud,object-storage,Node.js,Npm,Ibm Cloud,Object Storage,我正在尝试将图像上载到对象存储容器,并使用node js应用程序获取部署在bluemix上的图像的url。为此,我需要使用post或put api调用。我可以通过对象存储进行身份验证,但无法通过api调用实现功能。因此,我需要一些api调用方面的帮助。如果您曾经使用对象存储上的图像处理过此类api调用,那么有人能在这方面帮助我吗。(使用对象存储npm)。甚至可以共享任何类型的示例工作api调用。感谢您的帮助。对象存储api源自OpenStack Swift api规范。要将任何类型的对象添加到B

我正在尝试将图像上载到对象存储容器,并使用node js应用程序获取部署在bluemix上的图像的url。为此,我需要使用post或put api调用。我可以通过对象存储进行身份验证,但无法通过api调用实现功能。因此,我需要一些api调用方面的帮助。如果您曾经使用对象存储上的图像处理过此类api调用,那么有人能在这方面帮助我吗。(使用对象存储npm)。甚至可以共享任何类型的示例工作api调用。感谢您的帮助。

对象存储api源自OpenStack Swift api规范。要将任何类型的对象添加到Bluemix对象存储容器,您需要做两件事:

  • 向对象存储实例进行身份验证以获取授权令牌
  • 使用获得的令牌在容器上执行操作
  • 我假设您已经可以访问对象存储服务提供的JSON凭据。。。类似于:

    {
    
     "auth_url": "https://identity.open.softlayer.com",
    
     "domainId": "nice_long_hex_value",
    
     "domainName": "some_number",
    
     "password": "not_gonna_tell_you",
    
     "project": "object_storage_hex_value",
    
     "projectId": "project_hex_value",
    
     "region": "dallas",
    
     "userId": "another_fine_hex_value",
    
     "username": "some_text_with_hex_values"
    }
    
    步骤1:获取X-Auth-token。4项(用户名、用户名、密码和认证url)应来自您提供的凭据。

    具体而言,我们希望以以下形式标识Swift对象存储API url:
    https://dal.objectstorage.open.softlayer.com/v1/AUTH_some-hex-value
    是 链接到所需的对象存储区域(达拉斯,伦敦,…),并与公共接口关联。这将在端点部分中找到,其中包括名称“swift”

    更重要的是,在这个/v3/auth/tokens调用生成的HTTP响应头中有一个身份验证令牌,我们还需要记录该令牌,以便于后续的身份验证HTTP API调用

    下面是HTTP响应头的示例

    Connection: Keep-Alive
    Content-Length: 12089
    Content-Type: application/json
    Date: Wed, 09 Mar 2016 19:26:39 GMT
    Keep-Alive: timeout=5, max=21
    Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_wsgi/3.4 Python/2.7.5
    Vary: X-Auth-Token
    X-Subject-Token: gAAAAABW4Hjv5O8yQRwYbkV81s7KC0mTxlh_tXTFtzDEf3ejsP_CByfvvupOeVWWcWrB6pfVbUyG5THZ6qM1-BiQcBUo1WJOHWDzMMrEB5nru69XBd-J5f5GISOGFjIxPPnNmEDZT_pahnBwaBQiJ8vrg9p5obdtRJeuxk7ADVRQFcBcRhAL-PI
    x-openstack-request-id: req-26a078fe-d0a7-4a75-b32d-89d3461c55f1
    
    X-Subject-Token是重要的响应头。它的值将使用标头X-Auth-Token在所有后续HTTP请求标头中重用。很明显,对吧

    步骤2:使用这个标记,我们将一个对象添加到名为“ibmjstart”的容器中


    如果一切顺利,这将产生一个名为ibmjstart的新容器,其中包含一个名为test.txt的文本文件,其中只有一行内容。

    我听说这些API中的一些已被弃用。对于对象操作的新方法,是否有任何更新?谢谢
    {
      "token": {
        "methods": [
          "password"
        ],
        "roles": [
          {
            "id": "redacted",
            "name": "ObjectStorageOperator"
          }
        ],
        "expires_at": "2016-03-09T20:26:39.192753Z",
        "project": {
          "domain": {
            "id": "some_hex_value",
            "name": "some_int"
          },
          "id": "another_hex_value",
          "name": "one_more_hex_value"
        },
        "catalog": [
            ...
          {
            "endpoints": [
              {
                "region_id": "london",
                ...
              },
              {
                ...
              },
              {
                "region_id": "dallas",
                "url": "https://dal.objectstorage.open.softlayer.com/v1/AUTH_",
                "region": "dallas",
                "interface": "public",
                "id": "some_unique_id"
              },
              {
                ...
              },
              {
                ...
              },
              {
                ...
              }
            ],
            "type": "object-store",
            "id": "hex_values_rock",
            "name": "swift"
          },
          ...
        ],
        "extras": {},
        "user": {
          "domain": {
            "id": "hex_value",
            "name": "another_fine_int"
          },
          "id": "tired_of_hex_values_yet?",
          "name": "cheers_one_more_hex_value_for_the_road"
        },
        ...
      }
    }
    
    Connection: Keep-Alive
    Content-Length: 12089
    Content-Type: application/json
    Date: Wed, 09 Mar 2016 19:26:39 GMT
    Keep-Alive: timeout=5, max=21
    Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips mod_wsgi/3.4 Python/2.7.5
    Vary: X-Auth-Token
    X-Subject-Token: gAAAAABW4Hjv5O8yQRwYbkV81s7KC0mTxlh_tXTFtzDEf3ejsP_CByfvvupOeVWWcWrB6pfVbUyG5THZ6qM1-BiQcBUo1WJOHWDzMMrEB5nru69XBd-J5f5GISOGFjIxPPnNmEDZT_pahnBwaBQiJ8vrg9p5obdtRJeuxk7ADVRQFcBcRhAL-PI
    x-openstack-request-id: req-26a078fe-d0a7-4a75-b32d-89d3461c55f1
    
    curl -s -X PUT -i -H "Content-Type: text/plain"\
        -H "X-Auth-Token: X-Subject-Token from above"\
        -H "Cache-Control: no-cache"\
      -d "Awesome sauce is best served warm" "{API AUTH URL obtained above}/ibmjstart/test.txt"