當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript aws-sdk.S3類代碼示例

本文整理匯總了TypeScript中aws-sdk.S3的典型用法代碼示例。如果您正苦於以下問題:TypeScript S3類的具體用法?TypeScript S3怎麽用?TypeScript S3使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了S3類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: returnPdf

  // Returns the S3 url or local file path
  async returnPdf(options?: PdfOptions): Promise<string> {
    const data = await pdf(this.client, options)

    // check if S3 configured
    if (
      process.env['CHROMELESS_S3_BUCKET_NAME'] &&
      process.env['CHROMELESS_S3_BUCKET_URL']
    ) {
      const s3Path = `${cuid()}.pdf`
      const s3 = new AWS.S3()
      await s3
        .putObject({
          Bucket: process.env['CHROMELESS_S3_BUCKET_NAME'],
          Key: s3Path,
          ContentType: 'application/pdf',
          ACL: 'public-read',
          Body: new Buffer(data, 'base64'),
        })
        .promise()

      return `https://${process.env['CHROMELESS_S3_BUCKET_URL']}/${s3Path}`
    } else {
      // write to `${os.tmpdir()}` instead
      const filePath = path.join(os.tmpdir(), `${cuid()}.pdf`)
      fs.writeFileSync(filePath, Buffer.from(data, 'base64'))

      return filePath
    }
  }
開發者ID:xw616525957,項目名稱:chromeless,代碼行數:30,代碼來源:local-runtime.ts

示例2: returnScreenshot

  // Returns the S3 url or local file path
  async returnScreenshot(): Promise<string> {
    const data = await screenshot(this.client)

    // check if S3 configured
    if (process.env['CHROMELESS_S3_BUCKET_NAME'] && process.env['CHROMELESS_S3_BUCKET_URL']) {
      const s3Path = `${cuid()}.png`
      const s3 = new AWS.S3()
      await s3.putObject({
        Bucket: process.env['CHROMELESS_S3_BUCKET_NAME'],
        Key: s3Path,
        ContentType: 'image/png',
        ACL: 'public-read',
        Body: new Buffer(data, 'base64'),
      }).promise()

      return `https://${process.env['CHROMELESS_S3_BUCKET_URL']}/${s3Path}`
    }

    // write to `/tmp` instead
    else {
      const filePath = `/tmp/${cuid()}.png`
      fs.writeFileSync(filePath, Buffer.from(data, 'base64'))

      return filePath
    }
  }
開發者ID:KhaledNobani,項目名稱:chromeless,代碼行數:27,代碼來源:local-runtime.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: deploy

 async deploy(args) {
   this._s3 = new (this._getAWS(this.resources)).S3();
   let bucket = this.resources.target;
   let source = path.resolve(this.resources.source);
   this.bucket = bucket;
   this.source = source;
   console.log("Deploy", source, "on S3 Bucket", bucket);
   await this.createBucket(bucket);
   let files = Finder.from(source).findFiles();
   // Should implement multithread here - cleaning too
   for (let i in files) {
     let file = files[i];
     let key = path.relative(source, file);
     // Need to have mimetype to serve the content correctly
     let mimetype = mime.contentType(path.extname(file));
     await this._s3
       .putObject({
         Bucket: bucket,
         Body: fs.createReadStream(file),
         Key: key,
         ContentType: mimetype
       })
       .promise();
     console.log("Uploaded", file, "to", key, "(" + mimetype + ")");
   }
   if (!this.resources.staticWebsite) {
     return;
   }
   await this._createWebsite();
 }
開發者ID:loopingz,項目名稱:webda-shell,代碼行數:30,代碼來源:s3.ts

示例5: 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

示例6: storeImage

  public storeImage(buffer: Buffer): Promise<string> {
    const key = this.randomPath()
    const region = process.env.SLACKBOT_S3_BUCKET_REGION
    const domain = region && (region !== "us-east-1") ?
      `s3-${process.env.SLACKBOT_S3_BUCKET_REGION}.amazonaws.com`
    :
      "s3.amazonaws.com"

    const params = {
      ACL: "public-read",
      Body: buffer,
      Bucket: process.env.SLACKBOT_S3_BUCKET,
      ContentType: "image/png",
      Key: key,
    }

    const s3 = new AWS.S3({
      endpoint: new AWS.Endpoint(domain) as any,
    })

    return new Promise<string>((resolve, reject) => {
      s3.putObject(params, (err, data) => {
        if (err) {
          reject(`S3 Error: ${err.message}`)
        } else {
          resolve(`https://${domain}/${params.Bucket}/${key}`)
        }
      })
    })

  }
開發者ID:DipJar,項目名稱:looker-slackbot,代碼行數:31,代碼來源:amazon_s3_store.ts

示例7: saveToS3

 async saveToS3(id, manifest) {
   const s3 = new S3();
   return new Promise((resolve, reject) => {
     s3.upload({ Body: JSON.stringify(manifest), Bucket: this.registryBucket, Key: id}, (err, res) => {
       if (err) return reject(err);
       resolve(res);
     })
   });
 }
開發者ID:tbtimes,項目名稱:lede-cli,代碼行數:9,代碼來源:default.fetcher.ts

示例8: getPublicUrl

 /**
  * Fetch a public url for the resource.
  */
 private getPublicUrl(key: string) {
   return this.s3.getSignedUrl('getObject', {
     Bucket: getConfig().BUCKET_NAME,
     Key: key,
     Expires: 24 * 60 * 30,
   });
 }
開發者ID:terrylau2013,項目名稱:voice-web,代碼行數:10,代碼來源:bucket.ts

示例9: 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

示例10: Promise

 return new Promise((ok, fail) => {
   s3.putObject(args, (err, data) => {
     if (err) {
       return fail(err);
     }
     ok();
   });
 });
開發者ID:colinmathews,項目名稱:s3-append,代碼行數:8,代碼來源:s3-consolidator.ts


注:本文中的aws-sdk.S3類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。