当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript S3.getObject方法代码示例

本文整理汇总了TypeScript中aws-sdk.S3.getObject方法的典型用法代码示例。如果您正苦于以下问题:TypeScript S3.getObject方法的具体用法?TypeScript S3.getObject怎么用?TypeScript S3.getObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aws-sdk.S3的用法示例。


在下文中一共展示了S3.getObject方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: Promise

 return new Promise((resolve, reject) => {
   s3.getObject({ Bucket, Key })
     .on("httpDone", x => {
       resolve(JSON.parse(x.httpResponse.body.toString()));
     })
     .send();
 });
开发者ID:tbtimes,项目名称:lede-cli,代码行数:7,代码来源:default.fetcher.ts

示例2: runS3Script

 runS3Script(cb: {(err: Error | null, res: any)}) {
   this.s3.getObject({Bucket: this.bucket!, Key: this.scriptUrl!}, (err, resp) => {
     if (err) return cb(err, null)
     const script = resp.Body.toString('utf8')
     this.runScript(script, cb)
   })
 }
开发者ID:instructure,项目名称:ftl-engine,代码行数:7,代码来源:script.ts

示例3: Promise

 return new Promise((resolve, reject) => {
   const s3 = new AWS.S3({
     accessKeyId, secretAccessKey,
     region: region || 'ap-northeast-1',
     apiVersion: '2006-03-01'
   });
   return s3.getObject({ Bucket: bucket, Key: key }, (error, data) => {
     if (error) {
       reject(error);
     } else {
       resolve(JSON.parse(data.Body));
     }
   });
 });
开发者ID:bouzuya,项目名称:alertwil,代码行数:14,代码来源:s3.ts

示例4: Promise

 return new Promise((ok, fail) => {
   let args = {
     Bucket: this.config.bucket,
     Key: this.encodeKey(key)
   };
   this.s3.getObject(args, (err, data) => {
     if (err) {
       if (err.code === 'NoSuchKey' || err.code === 'AccessDenied') {
         return ok(null);
       }
       return fail(err);
     }
     let raw = data.Body.toString();
     ok(new FileContents(key, data.LastModified, data.ContentType, raw));
   });
 });
开发者ID:colinmathews,项目名称:s3-append,代码行数:16,代码来源:s3-consolidator.ts

示例5: callbackRuntime

export default callbackRuntime(async (event: APIGatewayEvent) => {
  // NOTE currently needed for backward compatibility
  if (event.path.split('/')[1] !== 'v1') {
    try {
      // log projectId of projects using the old API version
      const client = new GraphQLClient(process.env['GRAPHCOOL_ENDPOINT']!, {
        headers: {
          Authorization: `Bearer ${process.env['GRAPHCOOL_PAT']}`,
        },
      })

      await client.request(`mutation {
        createApiUser(projectId: "${event.path.split('/')[1]}") { id }
      }`)
    } catch (e) {
      if (e.response.errors[0].code !== 3010) {
        throw e
      }
    }

    return {
      statusCode: 301,
      body: '',
      headers: {
        Location: `https://images.graph.cool/v1${event.path}`,
      },
    }
  }

  const [paramsErr, params] = parseParams(event.path)

  if (paramsErr) {
    return {
      statusCode: 400,
      body: paramsErr.toString(),
    }
  }

  const { projectId, fileSecret, crop, resize } = params!

  const options = {
    Bucket: process.env['BUCKET_NAME']!,
    Key: `${projectId}/${fileSecret}`,
  }

  const {
    ContentLength,
    ContentType,
    ContentDisposition,
  } = await s3.headObject(options).promise()

  if (ContentLength! > 25 * 1024 * 1024) {
    return {
      statusCode: 400,
      body: 'File too big',
    }
  }

  if (!ContentType!.includes('image')) {
    return {
      statusCode: 400,
      body: 'File not an image',
    }
  }

  // return original for gifs, svgs or no params
  if (
    ContentType === 'image/gif' ||
    ContentType === 'image/svg+xml' ||
    (resize === undefined && crop === undefined)
  ) {
    const obj = await s3.getObject(options).promise()
    const body = (obj.Body as Buffer).toString('base64')
    return base64Response(body, ContentType!, ContentDisposition!)
  }

  const s3Resp = await s3.getObject(options).promise()
  const stream = sharp(s3Resp.Body)

  try {
    const config = getConfig({ resize, crop })

    stream.limitInputPixels(false)

    if (config.crop) {
      stream.extract({
        left: config.crop.x,
        top: config.crop.y,
        width: config.crop.width,
        height: config.crop.height,
      })
    }

    if (config.resize) {
      stream.rotate()
      stream.resize(config.resize.width, config.resize.height)

      if (config.resize.force) {
        stream.ignoreAspectRatio()
      } else {
//.........这里部分代码省略.........
开发者ID:morristech,项目名称:serverless-image-proxy,代码行数:101,代码来源:handler.ts


注:本文中的aws-sdk.S3.getObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。