【问题标题】:How to do the CURD operation in IBM Object Storage in nodejs如何在 node js 中在 IBM Object Storage 中进行 CRUD 操作
【发布时间】:2020-01-07 11:41:24
【问题描述】:

我正在尝试在 NodeJS 中使用 ATS API 实现 IBM 云对象存储。

是否有任何与使用 NodeJS 检索的云 API 对象中的 CRUD 操作相关的示例?

【问题讨论】:

  • I am trying to implement,你试过什么?请发布您的实现代码

标签: node.js ibm-cloud


【解决方案1】:

试试这个 NPM 包,它可以很好地完成工作 https://www.npmjs.com/package/ibm-cos-sdk。 这是来自 npm 包文档的示例代码:

    var AWS = require('ibm-cos-sdk');
    var util = require('util');

    var config = {
        endpoint: '<endpoint>',
        apiKeyId: '<api-key>',
        serviceInstanceId: '<resource-instance-id>',
    };

    var cos = new AWS.S3(config);

    function doCreateBucket() {
        console.log('Creating bucket');
        return cos.createBucket({
            Bucket: 'my-bucket',
            CreateBucketConfiguration: {
              LocationConstraint: 'us-standard'
            },
        }).promise();
    }

    function doCreateObject() {
        console.log('Creating object');
        return cos.putObject({
            Bucket: 'my-bucket',
            Key: 'foo',
            Body: 'bar'
        }).promise();
    }

    function doDeleteObject() {
        console.log('Deleting object');
        return cos.deleteObject({
            Bucket: 'my-bucket',
            Key: 'foo'
        }).promise();
    }

    function doDeleteBucket() {
        console.log('Deleting bucket');
        return cos.deleteBucket({
            Bucket: 'my-bucket'
        }).promise();
    }

    doCreateBucket()
        .then(doCreateObject)
        .then(doDeleteObject)
        .then(doDeleteBucket)
        .then(function() {
            console.log('Finished!');
        })
        .catch(function(err) {
            console.error('An error occurred:');
            console.error(util.inspect(err));
        });

【讨论】:

  • 如何进行重命名操作。我试图复制它不起作用的文件` cos.copyObject({ Bucket: 'file-ej22', Key: 'Files/', CopySource: 'file-ej22/Files/' }).promise().then(函数(数据){})`与无效复制源相关的电子获取错误
  • 这是一个新问题,需要更多详细信息,例如错误日志/堆栈跟踪。在发布问题之前,请尝试 google 并阅读发布问题的 stackoverflow 指南。
  • 错误`NoSuchKey:指定的键不存在。`
猜你喜欢
  • 1970-01-01
  • 2021-03-19
  • 1970-01-01
  • 2020-08-01
  • 2019-05-20
  • 1970-01-01
  • 2020-04-20
  • 2017-03-17
  • 2016-09-16
相关资源
最近更新 更多