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


TypeScript S3.headObject方法代码示例

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


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

示例1: getConfig

        clips.map(async ({ id, path, sentence }) => {
          // We get a 400 from the signed URL without this request
          await this.s3
            .headObject({
              Bucket: getConfig().BUCKET_NAME,
              Key: path,
            })
            .promise();

          return {
            id,
            glob: path.replace('.mp3', ''),
            text: sentence,
            sound: this.getPublicUrl(path),
          };
        })
开发者ID:terrylau2013,项目名称:voice-web,代码行数:16,代码来源:bucket.ts

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