IBM / ibm-cos-sdk-js

ibm-cos-sdk-js
Apache License 2.0
38 stars 20 forks source link

Having trouble using sample code from the documentation #80

Closed clu-7 closed 3 years ago

clu-7 commented 3 years ago

https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-node#node-examples-list-buckets

  1. We noticed is that the variable name isn't the same across code snippets making it hard to try out code.
const myCOS = require('ibm-cos-sdk');
var config = {
    endpoint: '<endpoint>',
    apiKeyId: '<api-key>',
    ibmAuthEndpoint: 'https://iam.cloud.ibm.com/identity/token',
    serviceInstanceId: '<resource-instance-id>',
};
var cosClient = new myCOS.S3(config);
function getBuckets() {
    console.log('Retrieving list of buckets');
    return cos.listBuckets()
    .promise()
    .then((data) => {
        if (data.Buckets != null) {
            for (var i = 0; i < data.Buckets.length; i++) {
                console.log(`Bucket Name: ${data.Buckets[i].Name}`);
            }
        }
    })
    .catch((e) => {
        console.error(`ERROR: ${e.code} - ${e.message}\n`);
    });
}

First time it uses cosClient second time is cos. Where can we go to ask for the documentation to be fixed? Is there any other tested documentation to use?

  1. Secondly trying the getBuckets() gave us this error:
    Retrieving list of buckets
    ERROR: XMLParserError - Non-whitespace before first tag.
    Line: 0
    Column: 1
    Char: {

We are using version: "ibm-cos-sdk": "^1.9.0". Tried all kinds of things to debug this (change xmlParser versions, etc) and believe it could be due to a downstream npm dependency error. Same issue reported here: https://github.com/aws/aws-sdk-js/issues/2623 in regards to this package https://www.npmjs.com/package/xml2js

We tried other version in the package.json but none of it is working. As a temporary result we are trying to use the REST API directly. Any guidance on how to proceed with the SDK?

nglange commented 3 years ago

Regarding the first point, the documentation has been updated to use the name cos for the client name in the example of client creation. Note that the name of the client is a variable, and can be set to any string that is best for organizing your code.