How to use ibm-cos-sdk - 10 common examples

To help you get started, we’ve selected a few ibm-cos-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github krhoyt / IBM / aggregator / functions / get-organization-summary / index.js View on Github external
// Last day of month
  // https://stackoverflow.com/questions/222309
  last = new Date( year, month + 1, 0 ).getDate();

  // Formalize
  // For use in query
  if( params.month || params.year ) {
    start = new Date( year, month, 1 );
    end = new Date( year, month, last );
  } else {
    start = new Date( year, month, now.getDate() );
    start.setDate( start.getDate() - 30 );
    end = new Date( year, month, now.getDate() );
  }

  let cos = new AWS.S3( {
    endpoint: params.COS_ENDPOINT,
    apiKeyId: params.COS_API_KEY,
    ibmAuthEndpoint: params.COS_AUTH_ENDPOINT,
    serviceInstanceId: params.COS_SERVICE_INSTANCE
  } );

  let item = await cos.getObject( {
    Bucket: params.COS_BUCKET, 
    Key: `${params.id}.zip`
  } )
  .promise()
  .then( (data ) => {
      return data;
  } )
  .catch( ( e ) => {
    console.log( `ERROR: ${e.code} - ${e.message}` );
github IBM / kui / packages / builder / dist / publishers / s3 / push-file.js View on Github external
.then(config => {
    const cos = new AWS.S3(config)
    debug('cos initialized')
    debug('creating bucket', Bucket)

    return cos
      .createBucket({
        Bucket,
        CreateBucketConfiguration: {
          LocationConstraint: 'us-standard'
        }
      })
      .promise()
      .catch(err => {
        if (err.code === 'BucketAlreadyExists' && process.env.EXIST_OK) {
          // when debugging, it is helpful to set EXIST_OK,
          // to reuse an existing bucket; for production
          // use, do not use this code path!
github cloud-annotations / training / src / commands / dump.js View on Github external
async function checkRegion(
  { region, access_key_id, secret_access_key },
  bucket
) {
  const config = {
    endpoint: cosEndpointBuilder(region, true),
    accessKeyId: access_key_id,
    secretAccessKey: secret_access_key
  }
  const cos = new COS.S3(config)
  try {
    // only returns if bucket is in region.
    await cos
      .getBucketLocation({ Bucket: bucket })
      .promise()
      .then(data => data.LocationConstraint)
    return true
  } catch {
    return false
  }
}
github cloud-annotations / training / src / commands / download.js View on Github external
const spinner = new Spinner()
  spinner.setMessage('Downloading model...')
  spinner.start()

  const {
    bucket,
    model_location
  } = run.entity.training_results_reference.location

  const { region, access_key_id, secret_access_key } = config.credentials.cos
  const cosConfig = {
    endpoint: cosEndpointBuilder(region, true),
    accessKeyId: access_key_id,
    secretAccessKey: secret_access_key
  }
  const cos = new COS.S3(cosConfig)

  await downloadDir(cos, bucket, model_location, 'model_ios')
  await downloadDir(cos, bucket, model_location, 'model_web')
  await downloadDir(cos, bucket, model_location, 'model_android')

  spinner.stop()
  console.log(`${green('success')} Download complete.`)
}
github IBM / kui / tools / travis / cleanBucket.js View on Github external
.then(config => {
      const cos = new AWS.S3(config)
      debug('cos initialized', config.apiKeyId)

      console.log('cleaning up bucket', Bucket)

      return cos
        .listObjects({ Bucket })
        .promise()
        .then(_ => {
          console.log('listObjects', _)
          return _
        })
        .then(({ Contents }) => Promise.all(Contents.map(({ Key }) => cos.deleteObject({ Bucket, Key }).promise())))
        .then(() => cos.deleteBucket({ Bucket }).promise())
    })
github cloud-annotations / training / src / commands / init.js View on Github external
async function checkRegion(
  { region, access_key_id, secret_access_key },
  bucket
) {
  const config = {
    endpoint: cosEndpointBuilder(region, true),
    accessKeyId: access_key_id,
    secretAccessKey: secret_access_key
  }
  const cos = new COS.S3(config)
  try {
    const region = await cos
      .getBucketLocation({ Bucket: bucket })
      .promise()
      .then(data => data.LocationConstraint)
    if (region) {
      return true
    }
    return false
  } catch {
    return false
  }
}
github cloud-annotations / training / src / commands / train2.js View on Github external
async function listBuckets({ region, access_key_id, secret_access_key }) {
  const config = {
    endpoint: cosEndpointBuilder(region, true),
    accessKeyId: access_key_id,
    secretAccessKey: secret_access_key
  }
  const cos = new COS.S3(config)
  return await cos
    .listBuckets()
    .promise()
    .then(data =>
      data.Buckets.map(bucket => {
        return bucket.Name
      })
    )
}
github cloud-annotations / training / src / commands / train2.js View on Github external
async function checkRegion(
  { region, access_key_id, secret_access_key },
  bucket
) {
  const config = {
    endpoint: cosEndpointBuilder(region, true),
    accessKeyId: access_key_id,
    secretAccessKey: secret_access_key
  }
  const cos = new COS.S3(config)
  try {
    const region = await cos
      .getBucketLocation({ Bucket: bucket })
      .promise()
      .then(data => data.LocationConstraint)
    if (region) {
      return true
    }
    return false
  } catch {
    return false
  }
}
github IBM / taxinomitis / serverless-functions / mltraining-images / src / ImageStore.ts View on Github external
public connect(): void {
        try {
            this.cos = new IBMCosSDK.S3(this.credentials);
        }
        catch (err) {
            log('imagestore connect', err);
            throw err;
        }
    }
github cloud-annotations / training / src / commands / dump.js View on Github external
async function listBuckets({ region, access_key_id, secret_access_key }) {
  const config = {
    endpoint: cosEndpointBuilder(region, true),
    accessKeyId: access_key_id,
    secretAccessKey: secret_access_key
  }
  const cos = new COS.S3(config)
  return await cos
    .listBuckets()
    .promise()
    .then(data =>
      data.Buckets.map(bucket => {
        return bucket.Name
      })
    )
}

ibm-cos-sdk

IBM SDK for JavaScript

Apache-2.0
Latest version published 1 day ago

Package Health Score

68 / 100
Full package analysis

Popular ibm-cos-sdk functions