Skip to content

Instantly share code, notes, and snippets.

@Alezco
Last active February 16, 2019 14:22
Show Gist options
  • Save Alezco/17efdd80b481c24d2a1455a7e5ad7aeb to your computer and use it in GitHub Desktop.
Save Alezco/17efdd80b481c24d2a1455a7e5ad7aeb to your computer and use it in GitHub Desktop.
Google Cloud Storage in Google Cloud Functions
const puppeteer = require('puppeteer');
const { Storage } = require('@google-cloud/storage');
const storage = new Storage({
projectId: 'your-gcp-project-id',
keyFilename: 'keyfile.json',
});
const BUCKET_NAME = 'your-gcp-bucket-name';
const BucketInstance = storage.bucket(BUCKET_NAME);
const browser = await puppeteer.launch(PUPPETEER_OPTIONS);
const page = await browser.newPage();
await page._client.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: '/tmp/',
});
await page.goto('https://example.com/', { waitUntil: 'load' });
await page.click('.downloadButton');
await BucketInstance.upload('/tmp/downloadedFile.pdf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment