當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。