Last active
February 16, 2019 14:22
-
-
Save Alezco/17efdd80b481c24d2a1455a7e5ad7aeb to your computer and use it in GitHub Desktop.
Google Cloud Storage in Google Cloud Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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