Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "ibm-cos-sdk in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'ibm-cos-sdk' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

// 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}` );
.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!
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
  }
}
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.`)
}
.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())
    })
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
  }
}
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
      })
    )
}
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
  }
}
public connect(): void {
        try {
            this.cos = new IBMCosSDK.S3(this.credentials);
        }
        catch (err) {
            log('imagestore connect', err);
            throw err;
        }
    }
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
      })
    )
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now