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


TypeScript S3.upload方法代碼示例

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


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

示例1: uploadFileToS3

  /**
  * Helper function upload file to s3
  * @param {any} bodyStream - binary64 for file
  * @param {string} filename
  * @method uploadFileToS3
  */
 public static async uploadFileToS3(bodyStream: any, filename: string) {
   console.log('upload to s3');
   const fileKey = `${uuid.v4()}_${filename}.pdf`;
   const response = await s3.upload({
     Key: fileKey.replace(/\s+/g, ''),
     Body: bodyStream,
     ACL: 'private'
   }).promise();
   return response;
 }
開發者ID:,項目名稱:,代碼行數:16,代碼來源:

示例2: Promise

 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,代碼行數:6,代碼來源:default.fetcher.ts

示例3: main

async function main() {
  const tData = await axios.get(
    'https://api.github.com/repos/prisma/prisma/releases'
  );
  const stableReleaseVersion = tData.data.filter(
    node => !node.tag_name.includes('alpha') && !node.tag_name.includes('beta')
  )[0].tag_name;
  console.log(`Version to publish: ${stableReleaseVersion}`);

  console.log('Creating binary');
  const buildResponse = spawnSync('npm', ['run', 'make-binary']);
  console.log(`Created binary.... ${buildResponse.stdout.toString()}`);

  const tarFileName = `prisma-${stableReleaseVersion}.tar.gz`;
  const tarResponse = spawnSync('tar', ['-cvzf', tarFileName, 'prisma']);
  console.log('made tar', tarResponse.stdout.toString());
  const shaResponse = spawnSync('shasum', ['-a', '256', tarFileName]);
  const shaValue = shaResponse.stdout
    .toString()
    .split(' ')[0]
    .trim();
  console.log(`shasum -a 256 ${tarFileName} => ${shaValue}`);

  console.log('Uploading tar to S3....this may take a while');

  const fileData = await fs.readFile(tarFileName);
  const s3 = new AWS.S3({ params: { timeout: 6000000 } });

  const s3Resp = await s3
    .upload({
      Bucket: 'homebrew-prisma',
      Key: tarFileName,
      Body: fileData,
      ACL: 'public-read'
    })
    .promise();
  console.log('Tar uploaded at location', s3Resp.Location);

  const uploadedBinaryURL = s3Resp.Location;
  console.log(`uploaded binary url ${uploadedBinaryURL}`);
  let homebrewDefinition = ``;
  const homeBrewTmp = `
class Prisma < Formula
  desc "Prisma turns your database into a realtime GraphQL API"
  homepage "https://github.com/prisma/prisma"
  url "https://s3-eu-west-1.amazonaws.com/homebrew-prisma/prisma-1.22.0.patch.1.tar.gz"
  sha256 "052cc310ab3eae8277e4d6fbf4848bc5c518af8e5165217a384bc26df82e63b9"
  version "1.22.0.patch.1"

  bottle :unneeded

  def install
    bin.install "prisma"
  end
end
  `;
  homeBrewTmp.split(/\r?\n/).forEach(line => {
    if (line.includes('version')) {
      homebrewDefinition += `  version "${stableReleaseVersion}"${os.EOL}`;
    } else if (line.includes('url')) {
      homebrewDefinition += `  url "${uploadedBinaryURL}"${os.EOL}`;
    } else if (line.includes('sha256')) {
      homebrewDefinition += `  sha256 "${shaValue}"${os.EOL}`;
    } else {
      homebrewDefinition += `${line}${os.EOL}`;
    }
  });

  await gitCommitPush({
    owner: 'prisma',
    repo: 'homebrew-prisma',
    token,
    files: [{ path: 'prisma.rb', content: homebrewDefinition }],
    fullyQualifiedRef: 'heads/automated-pr-branch',
    commitMessage: `bump version to ${stableReleaseVersion}`
  });

  const pullRes = await axios.post(
    'https://api.github.com/repos/prisma/homebrew-prisma/pulls',
    {
      title: `Automated PR for version ${stableReleaseVersion}`,
      head: 'automated-pr-branch',
      base: 'master',
      body: ' Automated PR generated via script',
      maintainer_can_modify: true
    }
  );
  console.log(
    `Pull Request created at ${
      pullRes.data.html_url
    }. Merge this to complete the release`
  );
}
開發者ID:dhruvcodeword,項目名稱:prisma,代碼行數:93,代碼來源:release-brew.ts


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